What we built
A detector-tracker-rules pipeline behind the official solution.detect_events interface. A fine-tuned YOLO finds road users and signal heads, ByteTrack links them into tracks, and a scene map of the junction is aligned to each clip with a SIFT homography. Ten per-class rule modules turn tracks and zones into time segments. A separate time-to-collision model scores accident risk for Part B. The same entry point backs the live demo. See the approach for the diagram and every rule.
Results on our dev labels
Scored with the unchanged evaluate.py against our own labels of the four sample clips (annotations/ground_truth.json, 80 events). Score A = 0.112 for predictions_samples.json. Micro F1 is 0.29 / 0.21 / 0.113 at IoU 0.3 / 0.5 / 0.7; ignoring labels it is 0.371 / 0.242 / 0.129. Part B cannot be scored here: the samples contain no accidents.
| Class | F1 @0.3 | F1 @0.5 | F1 @0.7 | TP | FP | FN |
|---|---|---|---|---|---|---|
| stop_line | 0.570 | 0.570 | 0.290 | 2 | 1 | 2 |
| jaywalking | 0.530 | 0.340 | 0.150 | 9 | 12 | 23 |
| solid_line_crossing | 0.140 | 0.140 | 0.140 | 1 | 5 | 7 |
| failure_to_yield | 0.050 | 0.050 | 0.050 | 1 | 10 | 26 |
| near_miss | 0 | 0 | 0 | 0 | 3 | 1 |
| red_light | 0 | 0 | 0 | 0 | 0 | 1 |
| illegal_turn | 0 | 0 | 0 | 0 | 0 | 4 |
| illegal_u_turn | 0 | 0 | 0 | 0 | 0 | 2 |
| congestion | 0 | 0 | 0 | 0 | 0 | 1 |
Ablations
Each step adds to the one above it; Score A on the same four clips.
| Change | Score A | Note |
|---|---|---|
| Earlier pipeline: 0.5 FPS on CPU, 1.5 s merge gap | 0.049 | |
| + 8 s merge gap for jaywalking | 0.062 | on the later preview run, 12 s gave 0.094 and 16 s 0.082 against 0.104, so 8 s stays |
| New rules at 2 FPS on every device (540p previews) | 0.070 | |
| + stop reporting wrong_way and stopped_vehicle | 0.085 | 43 and 10 false positives, 0 labelled events |
| + resolution-scaled stop line, preview alignment, solid-line clearance, near-miss fix | 0.104 | |
| + drop segments shorter than 1 s | 0.115 | F1 at IoU 0.7: 0.069 → 0.078 |
| Final: same code on the 4K originals (predictions_samples.json) | 0.112 |
Frame rate, on C3905 with the earlier rules: 0.5 FPS scored 0.000 and 5 FPS 0.022. We now sample 2 FPS on every device, so CPU and GPU runs give the same events. Minimum segment length:
| Minimum (s) | Score A | Mean F1 @0.7 |
|---|---|---|
| 0.500 | 0.104 | 0.069 |
| 1 | 0.115 | 0.078 |
| 1.500 | 0.117 | 0.080 |
| 2 | 0.118 | 0.077 |
| 3 | 0.119 | 0.078 |
We keep 1 s: longer minimums gain little and would delete genuine 1 s events such as red_light and short failure_to_yield crossings.
Error analysis
Of the 80 labelled events, 13 are matched at IoU 0.5, 23 are found but with boundaries too far off to match, and 44 have no same-class prediction at all. Jaywalking is mostly a boundary problem; failure_to_yield is mostly missed.
| Class | Matched | Boundaries off | Missed |
|---|---|---|---|
| jaywalking | 9 | 19 | 4 |
| failure_to_yield | 1 | 3 | 23 |
| solid_line_crossing | 1 | 1 | 6 |
| stop_line | 2 | 0 | 2 |
| illegal_turn | 0 | 0 | 4 |
| illegal_u_turn | 0 | 0 | 2 |
| congestion | 0 | 0 | 1 |
| red_light | 0 | 0 | 1 |
| near_miss | 0 | 0 | 1 |
Where the unmatched predictions fall. Most are the right class at the wrong time span; the main confusion is between pedestrian classes, since failure_to_yield and near_miss fire while someone is labelled as jaywalking.
| Predicted class | What it overlaps | Count |
|---|---|---|
| jaywalking | right class, boundaries off | 11 |
| failure_to_yield | right class, boundaries off | 3 |
| failure_to_yield | overlaps a labelled jaywalking | 3 |
| failure_to_yield | nothing labelled there | 3 |
| near_miss | overlaps a labelled jaywalking | 3 |
| solid_line_crossing | right class, boundaries off | 2 |
| other | overlaps a different labelled class | 5 |
| solid_line_crossing | nothing labelled there | 1 |
Why the model reports 44 events against 80 labels. Label merging is not the cause: merging overlapping same-class labels only took our 84 raw labels to 80. Most of the gap is failure_to_yield, where the model finds 11 events against 27 labelled and covers 37 s of the 221 s we labelled. Jaywalking is seen about as much (731 s predicted, 685 s labelled) but in fewer, longer segments (median 18 s against 8.5 s), because the 8 s merge gap joins nearby pedestrians. Four labelled classes are never predicted, and the 1 s minimum drops 16 short segments.
Our labels start and end on whole seconds, so each boundary can be up to 0.5 s off while predictions are frame-exact. For short events such as a 2 s failure_to_yield, rounding alone can push a correct prediction below IoU 0.7. Per-clip mismatches are listed under Failure cases on each sample page.
What worked
- Signal heads as detector classes. Red and green heads come out of the same detector pass, so red_light and stop_line need no extra model. The phase strip on the EDA page shows when each head is visible.
- Measuring the camera shift before trusting the map. The “fixed” camera moved by up to 38 px (at 720p) between clips. The alignment step brings the residual under 0.5 px on every sample, and it falls back to the original map with a logged reason when a match is unreliable.
- One shared scene map. Lanes, crossings, island and stop lines drawn once cover all 14 classes' spatial needs and carry over to the hidden set from the same camera.
What did not work, or not yet
- Four classes have no detector: accident, illegal_u_turn, road_obstacle and fire_smoke.
- Part B is uncalibrated. The sample clips contain no accidents, so the risk thresholds only keep false alarms rare on normal traffic. Part B also skips itself when there is no GPU or the time budget is too tight.
- Our dev set is small. We manually labelled all four provided clips and merged overlapping segments of the same class. It contains 22, 18, 29 and 11 event intervals respectively. Results on these clips may not generalise to unseen traffic or weather.
- Label definitions are ambiguous at the edges. Our first pass had long failure_to_yield and jaywalking spans that merged many people. Under the task's one-segment-per-overlap convention these become single long events, which is correct but hard to match at IoU 0.7.
- 4K decoding dominates runtime on CPU. Building this site's 540p previews from the 140 Mbit/s originals took several times real time on a 4-core laptop, before any detector ran. The GPU judging machine has the budget, but the CPU demo must limit clip length.
- Part of C3896 does not decode cleanly. ffmpeg reports corrupt H.264 packets in the original file. Decoding recovers and the clip plays to the end, but some frames can come out damaged, so a reader should expect failed reads and rules should not treat a missing frame as a stopped vehicle.
What we would do next
- Have a second reviewer audit the four labelled clips, then tune thresholds against F1 at IoU 0.7.
- Calibrate Part B on real collision footage so 0.5 means “probably within 5 s”, and turn its high-risk pairs with box contact into accident events.
- Decode on the GPU (NVDEC) and batch the detector to widen the time margin.
Links
- Repository: https://github.com/hvsniddin/traffic-analyzer
- Sample predictions: predictions_samples.json
- Weights: weights/
- Demo API contract: README