Skip to content

test: parity of the self-contained ONNX graph against detect_birds.py - #29

Merged
El1as42 merged 1 commit into
mainfrom
test/onnx-graph-parity
Oct 21, 2026
Merged

El1as42 merged 1 commit into
mainfrom
test/onnx-graph-parity

Conversation

@El1as42

@El1as42 El1as42 commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Adds tests/onnx_graph_parity.py: checks that a self-contained graph from src/inference/onnx_export.py (the one the browser demo runs) still reproduces detect_birds.py, the path the CLI and Streamlit use. tests/model_format_parity.py only covers the plain network exports, which run inside detect_birds.py.
  • The reference is configured from the graph's ONNX metadata: source model, species mapping, merge method, NMS IoU, conf and gap. That way the two sides differ only in implementation. Audio is resampled with librosa for both.
  • Same matching as the existing test: merged boxes are matched one-to-one at IoU ≥ 0.5, using the matcher and PASS/WARN thresholds of model_format_parity.py.
  • The verify_onnx docstring in onnx_export.py now points to the new test.
python tests/onnx_graph_parity.py --onnx docs/models/Just-Bird_fp16.onnx

Results

Run in birdbox-onnx (both sides on the CPU), on tests/test.wav plus the 12 parity soundscapes (13 recordings in total):

Graph Matched Extra Mean IoU Verdict
Just-Bird fp32 (fresh export) 1228/1228 0 1.0000 PASS
Just-Bird fp16 (docs/models) 1226/1228 3 0.9955 PASS

The fp32 graph matches the Python pipeline exactly. The remaining fp16 differences come from fp16 alone.

Correction to #25: the "ONNX fp32 99.7 %, mean IoU 0.999" row there came from a run where the .pt reference was on the GPU. Those 0.3 % were GPU-vs-CPU rounding, not the graph.

Test plan

  • python tests/onnx_graph_parity.py --onnx docs/models/Just-Bird_fp16.onnx <fp32 export> in birdbox-onnx: both PASS, exit code 0
  • Graphs of the other mappings (song merge, e.g. Western-US) were not run

🤖 Generated with Claude Code

tests/onnx_graph_parity.py builds the reference BirdCallDetector from the
graph's ONNX metadata (model, mapping, merge, NMS IoU, conf, gap), runs
both on tests/test.wav and the parity soundscapes, and matches the merged
boxes with the matcher and verdict of model_format_parity.py.

On CPU, Just-Bird fp32 matches 1228/1228 boxes (mean IoU 1.0000) and the
docs fp16 graph 1226/1228 (mean IoU 0.9955).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@El1as42
El1as42 merged commit 4f5ea21 into main Oct 21, 2026
1 check passed
@El1as42
El1as42 deleted the test/onnx-graph-parity branch October 21, 2026 12:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant