Skip to content

Commit c22e51d

Browse files
authored
perf(inference): optimize video pipeline metrics (#16)
Add warm-up-aware latency reporting, decode and write measurements, complete source-to-output metrics, running-total FPS calculation, tests, and documentation.
1 parent 45249b4 commit c22e51d

6 files changed

Lines changed: 254 additions & 15 deletions

File tree

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ performance, and deployment-oriented engineering.
4343
- Controlled PyTorch-vs-ONNX Runtime raw-backend benchmarking
4444
- Deterministic severity-based low-light, blur, and noise evaluation
4545
- Config-driven ONNX Runtime video and camera inference
46+
- Warm-up-aware end-to-end video pipeline profiling
4647

4748
## Dataset Ingestion
4849

@@ -203,6 +204,18 @@ must not be treated as complete real-road application performance.
203204
See [Config-Driven ONNX Video Inference](docs/video_inference.md)
204205
for commands, architecture, smoke-test evidence, and limitations.
205206

207+
## Video Pipeline Optimization
208+
209+
A controlled thread-count audit retained eight ONNX Runtime threads
210+
and identified inference as the dominant component.
211+
212+
The pipeline now excludes five warm-up frames, measures decode and
213+
video-writing latency separately, reports complete source-to-output
214+
throughput, and calculates running FPS using running totals.
215+
216+
See [End-to-End Video Pipeline Optimization](docs/video_optimization.md)
217+
for the audit, implementation, validation, and limitations.
218+
206219
## Benchmarking
207220

208221
The project includes a reproducible repeated-run inference benchmark.
@@ -236,11 +249,12 @@ Completed milestones:
236249
12. Controlled PyTorch-vs-ONNX Runtime CPU benchmarking
237250
13. Deterministic severity-based robustness evaluation
238251
14. Config-driven ONNX Runtime video inference
252+
15. Warm-up-aware end-to-end video pipeline optimization
239253

240254
Current milestone:
241255

242256
```text
243-
video inference completed -> end-to-end optimization -> Docker packaging
257+
end-to-end optimization completed -> real-world validation -> Docker packaging
244258
```
245259

246260
## Planned Technology Stack

configs/video_inference.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ runtime:
1717
iou: 0.60
1818
max_detections: 300
1919
max_frames: 0
20+
warmup_frames: 5
2021

2122
output:
2223
save_video: true

docs/video_inference.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ edge-traffic-video --config configs/video_inference.yaml --source input.mp4 --ou
5555
| Confidence threshold | 0.20 |
5656
| NMS IoU threshold | 0.60 |
5757
| Maximum detections | 300 |
58+
| Warm-up frames | 5 |
5859
| Default source | Camera index 0 |
5960
| Codec | mp4v |
6061
| Display window | Disabled |
@@ -145,6 +146,16 @@ The JSON report includes:
145146
- Camera capture, video writer, and display windows are released.
146147
- A zero-frame source is treated as a runtime failure.
147148

149+
## Optimization
150+
151+
The pipeline now excludes configurable warm-up frames, records
152+
decode and video-writing latency separately, reports complete
153+
source-to-output latency, and calculates running FPS using
154+
constant-time running totals.
155+
156+
See [End-to-End Video Pipeline Optimization](video_optimization.md)
157+
for the thread audit, validation, and remaining limitations.
158+
148159
## Limitations
149160

150161
- The controlled smoke source repeated one validation image.

docs/video_optimization.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# End-to-End Video Pipeline Optimization
2+
3+
## Audit evidence
4+
5+
A controlled 640 x 360 repeated-frame audit tested ONNX Runtime
6+
thread counts 1, 2, 4, 8, and 16. Each setting used 10 warm-up
7+
runs and 50 measured runs.
8+
9+
| Threads | Total mean | P95 | FPS | Bottleneck |
10+
|---:|---:|---:|---:|---|
11+
| 1 | 25.117 ms | 28.115 ms | 39.81 | Inference |
12+
| 2 | 17.231 ms | 23.765 ms | 58.03 | Inference |
13+
| 4 | 13.267 ms | 15.894 ms | 75.37 | Inference |
14+
| 8 | 11.942 ms | 12.429 ms | 83.74 | Inference |
15+
| 16 | 33.209 ms | 42.960 ms | 30.11 | Postprocessing |
16+
17+
Eight threads remain configured because they produced the best
18+
controlled complete-pipeline mean latency.
19+
20+
## Implemented changes
21+
22+
- Add five configurable warm-up frames.
23+
- Exclude warm-up frames from reported statistics.
24+
- Measure OpenCV frame-decoding latency.
25+
- Measure annotated-video writing latency.
26+
- Preserve processing-only latency.
27+
- Add complete source-to-output latency.
28+
- Replace latency-history copying with running totals.
29+
- Report processed, warm-up, and measured frame counts.
30+
- Fall back to all frames when a source is shorter than warm-up.
31+
32+
## Controlled validation
33+
34+
| Measurement | Result |
35+
|---|---:|
36+
| Frames processed | 40 |
37+
| Frames measured | 35 |
38+
| Total detections | 73 |
39+
| Mean decode latency | 0.2895 ms |
40+
| Mean preprocessing latency | 0.7911 ms |
41+
| Mean inference latency | 8.2303 ms |
42+
| Mean postprocessing latency | 1.3188 ms |
43+
| Mean rendering latency | 0.2413 ms |
44+
| Mean video-writing latency | 1.1832 ms |
45+
| Mean processing latency | 11.7716 ms |
46+
| Processing P95 | 12.7646 ms |
47+
| Processing throughput | 84.95 FPS |
48+
| Mean source-to-output latency | 12.0628 ms |
49+
| Source-to-output P95 | 13.0193 ms |
50+
| Source-to-output throughput | 82.90 FPS |
51+
| Annotated frames decoded | 40 |
52+
53+
## Limitations
54+
55+
- The source repeats one validation image.
56+
- The measurements describe this CPU, resolution, codec, and environment.
57+
- VideoWriter timing may not include final buffered disk flush.
58+
- Real-road, webcam, 720p, 1080p, and long-run testing remain separate.

0 commit comments

Comments
 (0)