ONNX AI Model
AI & Machine LearningONNX exchanges machine-learning models. Inference depends on input names/shapes/types, operator versions and runtime support. Weights may be external, so the model file alone may be incomplete.
- What it is used for
- Exchange of machine-learning graphs and weights
- What the file contains
- Binary data
All sections, questions and sources
Content reviewed: · Editor:Kai
Opening steps
Choose your environment or purpose to see its steps.
Menu labels and support vary by app, OS and version. Preserve the original before making changes.
Troubleshooting by symptom
- Input mismatch: inspect names, types, layout/batch dimensions and preprocessing.
- Unsupported operation: check opset, custom operators and runtime compatibility.
- Missing weights: inspect external-data names and paths relative to the model.
- Shape mismatch: inspect axis layout and batching rather than merely changing dimensions.
- GPU selection is slow: inspect actual provider use and CPU execution of unsupported operations.
- Moving the model breaks loading: copy external weights with their relative structure.
Training model → ONNX
- Use the framework’s supported exporter with suitable sample inputs and target opset.
- Compare outputs on matching inputs and inspect precision, dynamic shapes and external data.
- Compare output shapes, values and timing with the same input before/after export; retain definitions and export settings.
Renaming is not conversion; export support is not universal.
Building the correct input
Treat names, types, dimensions and axis order as one contract; images also require matching value ranges and color order.
Numerical output alone is insufficient; align label order and postprocessing and compare known cases.
Source for these steps:ONNX Project · ONNX Concepts / ONNX Project · External Data / ONNX Runtime Project · Python API overview
Single-file models and external data
ONNX may keep large tensors outside the graph file; transferring only the graph can omit weights.
Include a manifest, runtime information and reference output; check opsets and custom operators at the destination.
Source for these steps:ONNX Project · ONNX Concepts / ONNX Project · External Data / ONNX Runtime Project · Python API overview
Related-format differences
| Format | Main role | What to check |
|---|---|---|
| ONNX | Graph/inference interchange | Inspect external data and opsets |
| PT | PyTorch artifact | Identify architecture and save method |
| ENGINE | Optimized TensorRT artifact | Depends on hardware and build settings |
Handling and security
Review origin, license and memory needs; avoid unfamiliar custom-operator libraries and use updated runtimes.
Questions and answers
Is the ONNX alone sufficient?
External weights, preprocessing and a compatible runtime may be required.
What is opset?
The operator-specification version; check runtime support.
Can SAFETENSORS be renamed ONNX?
No; the structures, including model graphs, differ.
Does dynamic input accept any size?
Dynamic dimensions still have operator/export constraints; test the intended sizes.
Does validation prove equal accuracy?
Structural validity is separate from accuracy; compare predictions with identical preprocessing.
Format facts: name, steward and MIME type
- Formal name
- Open Neural Network Exchange
- Steward / specification
- ONNX project
- MIME type
- Depends on the producer or server; an extension alone does not establish a MIME type.
Primary and official sources
- Project documentationONNX Concepts
Explains model graphs, operators and inputs/outputs.
ONNX Project · Link checked: - Project documentationExternal Data
Documents externally stored tensor weights.
ONNX Project · Link checked: - Official documentationPython API overview
Documents session inputs and execution providers.
ONNX Runtime Project · Link checked: