fix: 修复10个关键bug提升系统稳定性和性能
1. YOLO11输出解析错误: 移除不存在的objectness行,正确使用class_scores.max() 2. CPU NMS逻辑错误: keep_mask同时标记保留和抑制框导致NMS失效,改用独立suppressed集合 3. 坐标映射缺失: _build_tracks中scale_info未使用,添加revert_boxes还原到ROI裁剪空间 4. batch=1限制: 恢复真正的动态batch推理(1~8),BatchPreprocessor支持多图stack 5. 帧率控制缺失: _read_frame添加time.monotonic()间隔控制,按target_fps跳帧 6. 拉流推理耦合: 新增独立推理线程(InferenceWorker),生产者-消费者模式解耦 7. 攒批形同虚设: 添加50ms攒批窗口+max_batch阈值,替代>=1立即处理 8. LeavePost双重等待: LEAVING确认后直接触发告警,不再进入OFF_DUTY二次等待 9. register_algorithm每帧调用: 添加_registered_keys缓存,O(1)快速路径跳过 10. GPU context线程安全: TensorRT infer()内部加锁,防止多线程CUDA context竞争 附带修复: - reset_algorithm中未定义algorithm_type变量(NameError) - update_roi_params中循环变量key覆盖外层key - AlertInfo缺少bind_id字段(TypeError) - _logger.log_alert在标准logger上不存在(AttributeError) - AlarmStateMachine死锁(Lock改为RLock) - ROICropper.create_mask坐标解析错误 - 更新测试用例适配新API Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -130,41 +130,36 @@ class TestLetterboxPreprocessor(unittest.TestCase):
|
||||
|
||||
class TestBatchPreprocessor(unittest.TestCase):
|
||||
"""测试Batch预处理器"""
|
||||
|
||||
|
||||
def test_preprocess_batch(self):
|
||||
"""测试批次预处理"""
|
||||
from core.preprocessor import BatchPreprocessor
|
||||
|
||||
|
||||
preprocessor = BatchPreprocessor(
|
||||
target_size=(480, 480),
|
||||
max_batch_size=4,
|
||||
fp16_mode=True
|
||||
)
|
||||
|
||||
|
||||
images = [
|
||||
np.zeros((640, 640, 3), dtype=np.uint8)
|
||||
for _ in range(2)
|
||||
]
|
||||
|
||||
|
||||
result, scale_info_list = preprocessor.preprocess_batch(images)
|
||||
|
||||
|
||||
self.assertEqual(result.shape[0], 2)
|
||||
self.assertEqual(len(scale_info_list), 2)
|
||||
|
||||
def test_memory_allocation(self):
|
||||
"""测试内存分配"""
|
||||
|
||||
def test_max_batch_size(self):
|
||||
"""测试最大batch大小"""
|
||||
from core.preprocessor import BatchPreprocessor
|
||||
|
||||
|
||||
preprocessor = BatchPreprocessor(
|
||||
target_size=(480, 480),
|
||||
max_batch_size=4,
|
||||
fp16_mode=True
|
||||
)
|
||||
|
||||
mem = preprocessor.allocate_batch_memory(2)
|
||||
|
||||
self.assertEqual(mem.shape[0], 2)
|
||||
self.assertEqual(mem.dtype, np.float16)
|
||||
|
||||
self.assertEqual(preprocessor.max_batch_size, 8)
|
||||
|
||||
|
||||
class TestImagePreprocessor(unittest.TestCase):
|
||||
@@ -200,12 +195,12 @@ class TestImagePreprocessor(unittest.TestCase):
|
||||
def test_get_statistics(self):
|
||||
"""测试获取统计"""
|
||||
from core.preprocessor import ImagePreprocessor
|
||||
|
||||
|
||||
preprocessor = ImagePreprocessor()
|
||||
stats = preprocessor.get_statistics()
|
||||
|
||||
|
||||
self.assertIn("config", stats)
|
||||
self.assertIn("memory", stats)
|
||||
self.assertIn("batch_size", stats["config"])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user