fix(perception): share tracking ONNX sessions across cameras - #477
Conversation
|
PPG seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
|
👋 感谢提交 PR @housq!维护者会尽快 review。 提交前请确认:
|
73290e5 to
970f0a3
Compare
[PR #477]: fix(perception): share tracking ONNX sessions across cameras作者: housq (Siqing Hou) 修改方案要解决的问题:每个摄像头通道独立创建检测(det_4C.onnx)和 ReID(human_body_reid_v2.onnx)的 ONNX InferenceSession,导致模型权重、原生线程池和分配器工作区在多通道间重复。三通道部署下跟踪模型 session 数为 6 个,RSS 偏高。 整体方案:引入 engine 级别的 session 池,在同一个 PerceptionEngine 的所有摄像头之间共享不可变的 ONNX 推理 session,同时保持每个摄像头的 tracker 状态(Kalman 滤波、track ID、embedding 历史)完全独立。
关键设计原则:
测试覆盖:
问题🔵 建议(可选优化)
结论LGTM — 设计清晰、实现完整。session 共享机制正确利用了 ORT InferenceSession 的并发安全性,关闭顺序保证 wrapper 引用先于共享缓存释放,向后兼容性好。测试覆盖了并发创建、多摄像头共享/隔离、关闭顺序等关键路径。三通道部署 RSS 从 ~5.36 GiB 降至 ~3.0 GiB(~40-45%)是显著优化。 由 review-pr skill v1.6 生成 |
What changed
TrackingModelResourcespool that lazily creates onedetector session and one ReID session
embedding history independent
Why
Each camera previously constructed its own detector and ReID
onnxruntime.InferenceSession. With multiple camera channels this duplicatedmodel weights, native thread pools, and allocator workspaces even though the
sessions are safe to use concurrently.
For three active camera channels, this changes the tracking model session count
from six to two without sharing mutable tracking state.
Impact
In a three-camera deployment, warm RSS decreased from roughly 5.36 GiB to about
3.0 GiB (around 40–45%). CPU inference frequency is unchanged by this PR.
The resource pool is optional at the tracking-service API boundary, so existing
standalone construction and tests keep the previous behavior.
Validation
cd backend && MILOCO_HOME=<isolated-dir> uv run pytest -qtyon the new production resource module