|
| 1 | +# Config-Driven ONNX Video Inference |
| 2 | + |
| 3 | +## Purpose |
| 4 | + |
| 5 | +This milestone adds sequential ONNX Runtime object detection for |
| 6 | +video files and camera sources. |
| 7 | + |
| 8 | +The workflow includes: |
| 9 | + |
| 10 | +- ONNX model and manifest validation |
| 11 | +- Camera-index and video-file source parsing |
| 12 | +- OpenCV frame decoding and encoding |
| 13 | +- Letterbox preprocessing |
| 14 | +- ONNX Runtime CPU inference |
| 15 | +- Confidence filtering and non-maximum suppression |
| 16 | +- Bounding-box, class-label, confidence, and FPS rendering |
| 17 | +- Atomic JSON report and annotated-video output |
| 18 | +- Configurable frame limits and output behavior |
| 19 | + |
| 20 | +## Command-line interface |
| 21 | + |
| 22 | +Run model-only preflight without opening a camera or video: |
| 23 | + |
| 24 | +~~~powershell |
| 25 | +edge-traffic-video --config configs/video_inference.yaml --preflight-only |
| 26 | +~~~ |
| 27 | + |
| 28 | +Run using the configured source: |
| 29 | + |
| 30 | +~~~powershell |
| 31 | +edge-traffic-video --config configs/video_inference.yaml |
| 32 | +~~~ |
| 33 | + |
| 34 | +Override the source and maximum processed frames: |
| 35 | + |
| 36 | +~~~powershell |
| 37 | +edge-traffic-video --config configs/video_inference.yaml --source input.mp4 --max-frames 300 |
| 38 | +~~~ |
| 39 | + |
| 40 | +Override generated artifact paths: |
| 41 | + |
| 42 | +~~~powershell |
| 43 | +edge-traffic-video --config configs/video_inference.yaml --source input.mp4 --output annotated.mp4 --report summary.json |
| 44 | +~~~ |
| 45 | + |
| 46 | +## Default configuration |
| 47 | + |
| 48 | +| Setting | Value | |
| 49 | +|---|---| |
| 50 | +| Backend | ONNX Runtime | |
| 51 | +| Provider | CPUExecutionProvider | |
| 52 | +| Threads | 8 | |
| 53 | +| Model input | 1 x 3 x 320 x 320 | |
| 54 | +| Classes | 10 | |
| 55 | +| Confidence threshold | 0.20 | |
| 56 | +| NMS IoU threshold | 0.60 | |
| 57 | +| Maximum detections | 300 | |
| 58 | +| Default source | Camera index 0 | |
| 59 | +| Codec | mp4v | |
| 60 | +| Display window | Disabled | |
| 61 | +| Save annotated video | Enabled | |
| 62 | +| Draw labels | Enabled | |
| 63 | +| Draw FPS | Enabled | |
| 64 | +| Overwrite existing outputs | Disabled | |
| 65 | + |
| 66 | +The confidence threshold of 0.20 is the selected operating point |
| 67 | +from the controlled 40-epoch model evaluation. |
| 68 | + |
| 69 | +## Processing pipeline |
| 70 | + |
| 71 | +Each decoded frame follows this sequence: |
| 72 | + |
| 73 | +1. Validate the decoded BGR frame. |
| 74 | +2. Apply 320 x 320 letterbox resizing. |
| 75 | +3. Convert BGR to RGB. |
| 76 | +4. Convert HWC pixels to contiguous NCHW float32. |
| 77 | +5. Normalize pixel values to the range 0 to 1. |
| 78 | +6. Run the ONNX graph using CPUExecutionProvider. |
| 79 | +7. Normalize raw detector output into channel-first format. |
| 80 | +8. Apply confidence filtering and non-maximum suppression. |
| 81 | +9. Rescale boxes to the original video-frame dimensions. |
| 82 | +10. Render boxes, labels, confidence scores, and processing FPS. |
| 83 | +11. Write the annotated frame when video output is enabled. |
| 84 | + |
| 85 | +## Controlled smoke test |
| 86 | + |
| 87 | +A deterministic 640 x 360 MP4 source was created from one real |
| 88 | +validation image. The source contained 24 repeated frames, and the |
| 89 | +CLI was limited to the first 12 frames. |
| 90 | + |
| 91 | +| Measurement | Result | |
| 92 | +|---|---:| |
| 93 | +| Frames processed | 12 | |
| 94 | +| Total detections | 13 | |
| 95 | +| Detections per frame | 1.0833 | |
| 96 | +| Mean preprocessing latency | 0.9389 ms | |
| 97 | +| Mean ONNX inference latency | 7.5867 ms | |
| 98 | +| Mean postprocessing latency | 7.3955 ms | |
| 99 | +| Mean rendering latency | 1.8829 ms | |
| 100 | +| Mean end-to-end processing latency | 18.9705 ms | |
| 101 | +| Measured processing throughput | 52.71 FPS | |
| 102 | +| Annotated frames decoded after writing | 12 | |
| 103 | +| Annotated-video size | 29856 bytes | |
| 104 | +| Completion reason | maximum_frames | |
| 105 | +| Manual visual inspection | Passed | |
| 106 | + |
| 107 | +The annotated output was manually inspected. Bounding boxes, |
| 108 | +class labels, confidence text, and the processing-FPS overlay |
| 109 | +were visibly present, and the video played correctly. |
| 110 | + |
| 111 | +## Generated outputs |
| 112 | + |
| 113 | +Default outputs: |
| 114 | + |
| 115 | +~~~text |
| 116 | +reports/video_inference/camera_annotated.mp4 |
| 117 | +reports/metrics/video_inference/video_summary.json |
| 118 | +~~~ |
| 119 | + |
| 120 | +Generated annotated videos and machine-specific JSON reports are |
| 121 | +excluded from Git. |
| 122 | + |
| 123 | +The JSON report includes: |
| 124 | + |
| 125 | +- Environment and package versions |
| 126 | +- ONNX model metadata and SHA-256 |
| 127 | +- Active execution providers |
| 128 | +- Source dimensions and frame rate |
| 129 | +- Processing settings |
| 130 | +- Frames and detection counts |
| 131 | +- Per-class detection counts |
| 132 | +- Completion reason |
| 133 | +- Preprocessing latency |
| 134 | +- ONNX inference latency |
| 135 | +- Postprocessing latency |
| 136 | +- Rendering latency |
| 137 | +- End-to-end processing latency and throughput |
| 138 | + |
| 139 | +## Safety and output behavior |
| 140 | + |
| 141 | +- Preflight never opens the configured source. |
| 142 | +- Existing outputs are rejected unless overwrite is enabled. |
| 143 | +- Temporary video output is removed after an unsuccessful run. |
| 144 | +- Completed output is moved atomically into its final path. |
| 145 | +- Camera capture, video writer, and display windows are released. |
| 146 | +- A zero-frame source is treated as a runtime failure. |
| 147 | + |
| 148 | +## Limitations |
| 149 | + |
| 150 | +- The controlled smoke source repeated one validation image. |
| 151 | +- The measured 52.71 FPS is processing throughput for this small, |
| 152 | + controlled local test and is not a complete real-road benchmark. |
| 153 | +- Video decoding and encoding performance depends on codec support. |
| 154 | +- Webcam behavior was not exercised during the controlled smoke test. |
| 155 | +- Detection counts across repeated frames are not unique object counts. |
| 156 | +- The pipeline performs frame-independent detection and does not track |
| 157 | + object identities across time. |
| 158 | +- The pipeline does not measure temporal consistency. |
| 159 | +- The current model retains its documented baseline-accuracy and |
| 160 | + robustness limitations. |
| 161 | +- Display-window responsiveness can vary by operating system. |
| 162 | +- Audio tracks are not preserved. |
0 commit comments