Skip to main content

Crate onnx_extractor

Crate onnx_extractor 

Source
Expand description

§onnx-extractor

A minimal ONNX model loader for extracting weights, tensors, operations, and graph structure.

This crate provides a simple interface to load ONNX models and extract:

  • Tensor weights & raw data (zero-copy slices, owned buffers, external files)
  • Tensor shapes, dimensions, and data types
  • Operations and attributes (nodes, inputs/outputs, subgraphs)
  • Graph topology and execution order

§Zero-Copy Design

Tensor::data() returns a TensorDataRef which borrows tensor data without copying:

  • Raw variant uses shared ownership (Bytes)
  • Numeric variants borrow directly (&[T])
  • Strings variant borrows elements (&[Bytes])

Tensor::into_data() returns owned TensorData without copying:

  • Raw variant returns shared ownership (Bytes)
  • Numeric variants return owned vectors (Vec<T>)
  • Strings variant returns owned vectors of shared elements (Vec<Bytes>)

Endianness: Raw tensor data uses little-endian byte order as defined in the ONNX specification. Typed fields use native host representation.

§Quick Start

use onnx_extractor::Model;

let model = Model::load_from_file("model.onnx")?;
println!("{}", model);

// Access tensor shape and data
if let Some(tensor) = model.graph().tensors().get("weight_1") {
    println!("Weight shape: {:?}", tensor.shape());
    let data = tensor.data()?;
    if let Some(bytes) = data.as_slice() {
        println!("Data size: {} bytes", bytes.len());
    }
}

Re-exports§

pub use attribute_value::AttributeValue;
pub use data_type::DataType;
pub use error::Error;
pub use graph::Graph;
pub use model::Model;
pub use operation::Operation;
pub use tensor::Tensor;
pub use tensor::TensorData;
pub use tensor::TensorDataRef;

Modules§

attribute_value
data_type
error
graph
model
operation
tensor

Structs§

Bytes
A cheaply cloneable and sliceable chunk of contiguous memory.