YOLO11 - ONNX to CGIR (experimental)¶
This sample starts with an Ultralytics YOLO11 object-detection checkpoint, exports an ONNX model, converts that model to a reusable CGIR artifact, and measures it on the GPU. It also shows the ONNX + WinMLCG Execution Provider path for testing CGC without keeping a CGIR file.
Before you start¶
Complete CGC environment setup and activate that virtual environment. Inspect the available EPs and devices:
Step 1: Export YOLO11 to ONNX¶
Install the exporter into the same environment:
Place the Ultralytics yolo11n.pt checkpoint in the current directory, then
export a static, batch-one FP32 model without ONNX simplification:
yolo export model=yolo11n.pt format=onnx imgsz=640 batch=1 dynamic=False simplify=False opset=17 device=cpu
This produces yolo11n.onnx with input shape [1, 3, 640, 640] and raw
detection output shape [1, 84, 8400].
Step 2: Benchmark ONNX¶
Test ONNX through the WinMLCG EP:
To test online CGIR conversion through the Windows ML Runtime API instead:
Step 3: Build CGIR¶
Generate the CGC build configuration:
Build the reusable .mlir model:
The default configuration applies FP16
conversion before exporting MLIR. FP16 can change accuracy; add --no-quant
to the build command to skip quantization.
Step 4: Benchmark CGIR¶
Run the converted model through the Windows ML Runtime API:
Step 5: Compare output tensors¶
Compare the CGIR model against the original FP32 ONNX model on ten generated inputs, using ONNX Runtime on CPU as the reference:
winml eval --mode compare -m .\model-cgir\model.mlir --runtime winml-runtime --reference .\yolo11n.onnx --reference-device cpu --samples 10 -o .\model-cgir\tensor-similarity.json
This checks raw output similarity, not object-detection accuracy. Inspect absolute errors as well as cosine similarity. Detection mAP still requires a labeled dataset with matching preprocessing and postprocessing and has not been validated by this sample.