detection_app.py 的主流程
入口脚本负责流程编排,模型细节下沉到后端模块。真实代码主流程如下:
labels = load_labels(args.labels)
model_path = resolve_model_path(args.model, args.backbone, model_dir, args.device)
backend = create_backend(args.device, model_path, args.device_id)
capture_context = open_capture_context(args.source, args.camera_profile, args.camera_mjpeg)
每帧循环中调用统一推理接口:
detections, profile_ms = backend.infer_with_profile(
frame,
args.score_threshold,
args.nms_threshold,
args.max_detections,
)
annotated = draw_detections(frame, detections, labels, fps, model_path.name, args.device, avg_timings_ms)
这段代码对应“解析参数 → 加载标签 → 找模型 → 创建后端 → 打开输入 → 逐帧推理 → 绘制”。