Principle:Onnx Onnx Model Loading
| Knowledge Sources | |
|---|---|
| Domains | Deserialization, Model_Persistence |
| Last Updated | 2026-02-10 00:00 GMT |
Overview
A deserialization mechanism that reads ONNX model files from disk into in-memory protobuf representations for inspection, validation, and transformation.
Description
Model loading is the inverse of serialization: it reads a byte stream from a file, deserializes it according to the detected format, and constructs an in-memory ModelProto object. The loader supports multiple formats (binary protobuf, text protobuf, JSON, ONNX text syntax) with automatic format detection based on file extension. It also handles external data by optionally loading tensor data from separate files referenced by the model.
This principle is the entry point for all model manipulation workflows: before a model can be validated, transformed, composed, or evaluated, it must first be loaded into memory.
Usage
Use this principle as the first step in any workflow that operates on existing ONNX models. This includes validation, version conversion, composition, evaluation, and external data handling. When external data is stored in a different directory from the model, load with load_external_data=False and then manually call load_external_data_for_model with the correct base directory.
Theoretical Basis
Deserialization maps a byte stream back to the in-memory object graph:
The loading pipeline:
- Read raw bytes from the file
- Detect serialization format from file extension (or use specified format)
- Deserialize bytes into a ModelProto protobuf message
- Optionally load external tensor data from referenced files