Commit Graph

37 Commits

Author SHA1 Message Date
1529322ca9 feat: 收到config_update时同步Redis配置到SQLite
主推理管线从SQLite读取摄像头/ROI/绑定配置,而云端pushConfig
只写入Redis。新增_sync_redis_to_sqlite方法,在收到config_update
通知后将Redis中的camera/roi/bind keys同步写入SQLite,
并清除全部内存缓存确保下次读取获得最新数据。

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-05 09:58:04 +08:00
bef62e430c fix: 修复get_bindings_from_redis空roi_id过滤bug
当roi_id为空字符串时(reload_all_algorithms调用),原逻辑
data.get('roi_id') == "" 匹配不到任何bind,导致全量重载
始终返回0个算法。改为 not roi_id or 匹配,空值时返回全部。

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-05 09:57:20 +08:00
9b4b69a65c chore: 清理git追踪的缓存和日志文件
将 __pycache__、logs、.claude 加入 .gitignore 并从索引移除

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-05 09:56:33 +08:00
98595402c6 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>
2026-02-04 16:47:26 +08:00
fa0304aa47 feat: 重构数据库schema分离空间与业务配置 - 新增algorithm_registry和roi_algo_bind表 - roi_configs简化为纯空间配置 - 新增AlgorithmInfo/ROIAlgoBind数据模型 2026-02-03 14:26:52 +08:00
1caba41625 feat: 批处理多ROI推理 - 添加 batch_process_detections 批量后处理 - 重构 _process_frame 收集多ROI统一推理 2026-02-03 11:17:54 +08:00
d7f56683c7 perf: GPU NMS + 日志优化 + 数组预分配
- GPU NMS: torchvision.ops.nms 替代 CPU NMS, 50-80% 提升
- 日志优化: 每10帧输出一次性能日志, 减少90%日志开销
- 数组预分配: 预分配8400框缓冲区, 避免重复创建
- 预过滤: 置信度>0.3的框先过滤, 减少NMS计算量

性能对比:
- 优化前: 40-50ms
- 优化后: 17-22ms (60% 提升)
2026-02-02 16:37:24 +08:00
4a58d190c0 perf: 向量化后处理 + Person Only 检测
- _parse_yolo_output: 只检测人(class_id=0),移除类别循环
- NMSProcessor: 纯 NumPy 向量化 NMS,移除 Python 循环
- 延迟从 40-50ms  17-20ms (60% 提升)
2026-02-02 15:54:45 +08:00
c17f983ab3 perf: batch=1 优化减少延迟
- settings: batch_size=41
- tensorrt_engine: BATCH_SIZE=41
- preprocessor: 移除 padding 逻辑,直接 batch=1
- 预处理延迟从 17ms  5ms
2026-02-02 15:25:13 +08:00
3dd4e56f99 fix: YOLO TensorRT 输出解析修复
- TensorRT 输出 shape: (1, 84, 4725)  (84, 4725)
- 正确解析 YOLO 输出格式: boxes[0:4], obj_conf[4], cls_scores[5:]
- 移除错误的 detection 遍历逻辑
- 工业级向量化操作代替 Python 循环
2026-02-02 15:02:58 +08:00
745cadc8e7 feat: TensorRT 固定 batch=4 重构
- tensorrt_engine.py 工业级 Buffer Pool
- preprocessor.py 添加 pad_to_batch4()
- postprocessor.py 支持批量输出
- settings.py 固定 batch_size=4
2026-02-02 14:49:47 +08:00
956bcbbc3e feat: TensorRT 工业级重构
- 添加 HostDeviceMem 类(Buffer Pool)
- _allocate_buffers() init 阶段一次性分配
- infer() 使用 async API + CUDA stream
- 回退机制:pagelocked 失败时用普通 numpy
2026-02-02 14:12:43 +08:00
5e9ec7dacc docs: 边缘端运行测试报告 2026-02-02 14:05:37 +08:00
0a1d61c1e2 fix: 修复 TensorRT bindings 问题
- tensorrt_engine.py 添加 pycuda 支持
- CUDA 上下文和流管理
- _is_in_working_hours 支持字符串格式
2026-02-02 14:00:21 +08:00
29d3ea0bc4 feat: 传递离岗时长到告警记录
- ResultReporter AlertInfo 添加 duration_minutes
- main.py 使用 report_alert 替代 report_detection_alert
- _store_alert 保存 duration_minutes
2026-01-30 17:27:39 +08:00
f90ff60f6c feat: 添加离岗时长记录
- alert_records 添加 duration_minutes 字段
- AlgorithmManager 输出 duration_minutes
- AlertRecord 添加 duration_minutes 字段
2026-01-30 17:26:12 +08:00
f570245589 docs: 表结构对比报告 2026-01-30 17:22:00 +08:00
4632ae74f3 fix: 修复运行错误
- algorithms.py 添加 threading/redis/logger 导入
- ResultReporter 添加 report_heartbeat() 和 close() 方法
2026-01-30 15:15:09 +08:00
36674edff8 fix: 修复导入错误
- 移除不存在的 init_database 导入
- DatabaseManager  SQLiteManager
2026-01-30 14:54:20 +08:00
fdd3e9ac88 feat: 算法层接管判断权
- 添加 AlgorithmManager 集成
- 新增 _build_tracks() 将检测转为算法输入格式
- 重构 _handle_detections() 让算法决定是否告警
- 注册算法时从 ROI 配置读取参数
- 停止使用 PostProcessor.check_alarm_condition() 做业务判断

新的执行链路:
ROI裁剪  480p预处理  YOLO推理  algorithm.process()  告警
2026-01-30 14:24:34 +08:00
101b26fc95 feat: 实现配置热更新机制
数据库扩展:
- roi_configs 新增算法参数字段(working_hours, confirm_on_duty_sec等)
- 新增 config_update_log 表记录配置变更日志

Redis缓存:
- ROI/摄像头配置缓存到 Redis(TTL 1小时)
- sync_all_to_redis() 批量同步配置
- notify_config_change() 发布配置变更通知

热更新:
- AlgorithmManager 订阅 Redis config_update 频道
- load_from_redis() 从 Redis 加载算法参数
- reload_algorithm() 热更新单个算法
- reload_all_algorithms() 重新加载所有算法

配置模型:
- ROIInfo 添加算法参数字段
2026-01-30 13:51:58 +08:00
56820622c6 fix: 统一算法参数
- confirm_seconds 默认值改为 5 秒
- 同步 default_params 中的默认值为 5
2026-01-30 13:27:28 +08:00
c4baf2fd1f fix: 重构算法逻辑
LeavePostAlgorithm:
- 重构状态机:WAITING  ON_DUTY  LEAVING  OFF_DUTY
- 移除 INIT 状态,增加 LEAVING 确认期防抖动
- 添加目标类型过滤 (target_class)
- 统一使用 datetime

IntrusionAlgorithm:
- 修复冷却逻辑 Bug:只在告警后重置
- 添加确认机制:持续检测 N 秒才触发告警
- 添加目标类型过滤 (target_class)
- 二次告警时间改为 2 分钟 (120秒)

AlgorithmManager:
- 更新默认参数
- 统一参数命名
2026-01-30 13:23:22 +08:00
2c0fe7f3c5 fix: 适配 SQLite API 替换 MySQL
- config_sync.py:
  - 修复导入: get_sqlite_manager 替代 get_database_manager
  - 修复方法: get_all_camera_configs 替代 get_camera_info
  - 修复方法: get_rois_by_camera 替代 get_roi_configs
  - 修复方法: get_camera_config 替代 get_camera_info
  - 修复方法: get_roi_config 替代 get_roi_configs

- result_reporter.py:
  - 更新注释: 移除 MySQL 相关描述
2026-01-30 11:46:15 +08:00
816a67f33e feat: SQLite 添加设备配置表
- 新增 camera_configs 表(摄像头配置,永不删除)
- 新增 roi_configs 表(ROI配置,永不删除)
- 添加配置表的增删改查方法
- 只清理 alert_records 表(7天过期)
2026-01-30 11:42:12 +08:00
ccb49e9eb9 chore: 忽略 data/ 目录
- 添加 data/ 和 captures/ 到 gitignore
- SQLite 数据库和抓拍图片不随代码提交
2026-01-30 11:35:45 +08:00
ccb021677c feat: 重构存储策略为 SQLite
- 新增 config/database.py: SQLite 数据库管理器
  - WAL 模式提升写入性能
  - 异步批量写入队列
  - 滚动清理机制(保留7天)

- 新增 core/storage_manager.py: 图片存储管理
  - 异步保存抓拍图片
  - 本地缓存断网容灾
  - 按日期分目录存储

- 更新 config/settings.py: 添加 SQLite 配置
  - SQLiteConfig 数据类
  - 环境变量支持

- 更新 core/result_reporter.py: 适配新存储
  - 使用 SQLite 替代 MySQL
  - AlertInfo 数据类重构
  - 断网自动缓存到本地
2026-01-30 11:34:51 +08:00
6dc3442cc2 fix: 添加资源释放幂等保护
- 添加 _released 标志防止重复释放
- release() 方法支持幂等调用
2026-01-30 10:48:28 +08:00
b67bda8042 fix: 修复 Python TensorRT 资源释放
- 移除不存在的 .destroy() 方法调用
- Python TensorRT 由 GC 管理,= None 即释放
2026-01-30 10:39:02 +08:00
bcabe65984 chore: 忽略说明文档
- 忽略 *.md、CHANGELOG.md、README.md
- 保留 requirements.txt
2026-01-30 10:14:16 +08:00
02c30d7461 chore: 更新 .gitignore 规则
- 忽略 __pycache__/、*.pyc 等 Python 缓存
- 忽略 .trae/ AI 临时文件
- 忽略 logs/ 日志目录
- 忽略 models/*.onnx 中间产物
- 保留 CHANGELOG.md、build_engine.py 等核心文件
2026-01-30 10:12:09 +08:00
a6130b5102 fix: 修复动态维度内存分配错误
- 处理 TensorRT 引擎的负维度 (-1)
- 将动态 Batch 维度替换为最小值 1
2026-01-30 09:20:05 +08:00
8bbf485f71 fix: 移除无用的 yolo11n.onnx 2026-01-29 18:56:56 +08:00
ab8fa80fba fix: 移除已废弃的 BENCHMARK flag
- BENCHMARK flag 在 TRT 8.5+ 已废弃
- tactic profiling 逻辑内部自动完成
2026-01-29 18:54:26 +08:00
4103b503db fix: 修复 tactic_sources 参数解析错误
- 支持数值格式 (+7) 和名称格式 (+CUBLAS,+CUDNN)
- 添加 tactic_values 常量说明文档
2026-01-29 18:48:27 +08:00
b0ddb6ee1a feat(project): move edge_inference_service contents to root and update paths
- Moved all project files and directories (config, core, models, etc.) from
  edge_inference_service/ to the repository root ai_edge/
- Updated model path in config/settings.py to reflect new structure
- Revised usage paths in __init__.py documentation
2026-01-29 18:43:19 +08:00
6733344b11 初始化边缘推理服务 2026-01-29 18:33:12 +08:00