Introduction
ONNX is an open format for trained neural networks, started by Facebook and Microsoft in 2017 and now run by the ONNX project. An ONNX file holds the whole network, both its graph of operations and its weights, so a model trained in one framework can run in another program or on another device. It is widely used to move models from PyTorch into ONNX Runtime and onto phones and embedded hardware.
Structure
An ONNX file is a single Protocol Buffers
message of type ModelProto, defined in the project’s
onnx.proto schema. It has no magic number of its own. Its main fields
are:
ir_version: the version of the ONNX formatopset_import: the operator sets the model uses, with their versionsproducer_nameandproducer_version: the program that wrote itgraph: the network itself, with its nodes (each an operator such asConvorMatMulwith named inputs and outputs), its inputs and outputs, and itsinitializertensors holding the weights
A Protocol Buffers message is limited to 2 GB, so large models keep their weights in
separate files beside the .onnx file, which refers to them by name.
Links
Software
- ONNX Runtime (Windows, macOS, Linux, Android, iOS, web)
- Netron, a viewer that draws the network (Windows, macOS, Linux, web)
- PyTorch, which exports models to ONNX
Developers
- onnx, Python package for loading, checking and editing models
- ONNX Runtime, with APIs for C, C++, C#, Java, Python and JavaScript
Reference
- ONNX documentation, including the operator list and the intermediate representation
- onnx.proto, the Protocol Buffers schema