Skip to main content

Module onnx

Module onnx 

Source
Expand description

ONNX format reader (GH-238)

Lightweight ONNX protobuf parser that extracts tensor initializers (weights) from .onnx files without requiring the prost crate.

§ONNX Protobuf Layout (simplified)

ModelProto {
  ir_version: int64        (field 1)
  graph: GraphProto        (field 7)
    initializer: [TensorProto]  (field 5, repeated)
      dims: [int64]        (field 1, repeated/packed)
      data_type: int32     (field 2)
      name: string         (field 8)
      raw_data: bytes      (field 13)
      float_data: [float]  (field 4, packed)
}

§Example

use aprender::format::onnx::OnnxReader;

let reader = OnnxReader::from_file("model.onnx")?;
for tensor in reader.tensors() {
    println!("{}: {:?} ({:?})", tensor.name, tensor.shape, tensor.data_type);
}

Structs§

OnnxMetadata
ONNX model metadata
OnnxReader
ONNX file reader
OnnxTensor
A tensor extracted from an ONNX file

Enums§

OnnxDataType
ONNX data types (from onnx.proto3 TensorProto.DataType)

Functions§

is_nemo_file
Check if a file is a NeMo archive (.nemo = tar.gz)
is_onnx_file
Check if a file is an ONNX model by reading the first few bytes