.ONNX
Open Neural Network Exchange
Introduction
ONNX is an open format for trained neural networks, started by Facebook and Microsoft in 2017. 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.
Software
- ONNX Runtime (Windows, macOS, Linux, Android, iOS, web)
- Netron, a viewer that draws the network (Windows, macOS, Linux, web)
- The onnx Python package, for checking and editing models
- PyTorch, which exports models to ONNX
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.