Check whether an ONNX export changes detections
Build an export comparison that measures quality as well as file size and runtime.
Opening the Python editor…
Requirements and learning goals
Before you start
- The Wendy starter project and inputs/scene.jpg from the YOLO walkthrough
- An empty-scene photograph saved as inputs/empty.jpg
You will be able to
- Export an ONNX model
- Compare original and exported predictions
- Keep reproducible model artifacts
The browser exercise above works without extra setup. The project brief below assumes the listed prerequisites and gives you a task and checks to perform. Need a guided first project?
Export converts a trained model into a format another runtime can execute, such as . uses lower-precision numbers to reduce memory or computation. Both can help a model fit an edge device, but can also change its predictions. Here you will compare an export with the original before attempting lower precision.
Use repeatable builds to deploy each model variant with its matching runtime, then compare accuracy and on the same target.
Keep the original as a baseline
Compare export and quantization separately using fixed images, preprocessing, and thresholds.
Use the same Wendy starter project from the walkthrough. Keep inputs/scene.jpg, add inputs/empty.jpg, and save this as export_compare.py beside detect.py. The runner copies those images and the bundled weights into the results directory:
from ultralytics import YOLO
original = YOLO("yolo11n.pt")
path = original.export(format="onnx", imgsz=640, simplify=False, opset=17)
exported = YOLO(path)
for name in ["scene.jpg", "empty.jpg"]:
a = original.predict(name, conf=0.25, imgsz=640, rect=False, device="cpu")[0]
b = exported.predict(name, conf=0.25, imgsz=640, rect=False, device="cpu")[0]
a.save(filename=f"original-{name}")
b.save(filename=f"exported-{name}")
print(name, len(a.boxes), len(b.boxes))Stop the previous attached run with Ctrl+C, then deploy the comparison to the same target:
wendy run --env LESSON_SCRIPT=export_compare.pyExpect yolo11n.onnx, four annotated images, and one log line per input with original and exported detection counts. Download them from the app's results page together with requirements-resolved.txt and run.log before redeploying.
The starter installs ONNX and ONNX Runtime during the image build and disables runtime package installation. This exercise disables graph simplification. If you choose other export options, add their dependencies to requirements.txt and rebuild with wendy run while online.
Compare more than counts
Open original-scene.jpg beside exported-scene.jpg, then compare the two empty-scene outputs. Look for changed labels, missing or extra boxes, and shifted edges even when counts match. A small score change can cross a threshold. For a larger set, match boxes by class and overlap using the evaluation exercise. Keep artifact checksums and package versions with the results.
Optional extension: quantization
This exercise produces a floating-point ONNX model. Quantization is a separate experiment that needs a chosen target runtime and calibration dataset. Static quantization uses representative calibration inputs; keep those separate from final evaluation. ONNX Runtime documents its quantization choices.
Make a table with file size, startup time, steady-state latency, and per-class mistakes. Lower precision does not guarantee faster execution if operations fall back to a different backend.
Common snag: blaming quantization for a preprocessing mismatch. Compare the original with floating-point export first. You are done when a teammate can reproduce the quality and speed tradeoff on the same inputs.
Before you move on
Can you do each of these?
- Export an ONNX model
- Compare original and exported predictions
- Keep reproducible model artifacts
0 of 2 checkpoints solved. Try checkpoint 1