Skip to main content

Model

Struct Model 

Source
pub struct Model {
    pub graph: Graph,
    pub metadata: ModelMetadata,
    /* private fields */
}
Expand description

An owned ONNX model: the shared-IR Graph plus the model-level metadata and (optionally) the live weight store backing external initializers.

Unlike onnx_runtime_loader::Model, which borrows a &Graph, this type owns its graph so it can be returned from load_model, inspected, dumped to text, validated, and written back out.

Fields§

§graph: Graph

The computation graph, in the shared onnx_runtime_ir IR.

§metadata: ModelMetadata

Model-level metadata not carried by the Graph itself.

Implementations§

Source§

impl Model

Source

pub fn new(graph: Graph) -> Self

Wrap an in-memory Graph as a model with default metadata.

The metadata’s opset_import is still taken from graph.opset_imports at save time; only the header fields (ir_version, producer, …) default.

Source

pub fn with_metadata(graph: Graph, metadata: ModelMetadata) -> Self

Wrap a Graph together with explicit model-level metadata.

Source

pub fn set_weights(&mut self, weights: Arc<WeightStore>)

Attach the live weight store backing external initializers.

Source

pub fn weights(&self) -> Option<&Arc<WeightStore>>

The live weight store, if this model carries one.

Source

pub fn from_proto(proto: ModelProto) -> Result<Self>

Construct a model from the complete generated ONNX protobuf.

The protobuf remains the serialization source of truth, while graph is populated as the runtime-compatible execution projection.

Source

pub fn to_proto(&self) -> Result<ModelProto>

Return the complete generated ONNX protobuf represented by this model.

Models parsed from protobuf JSON/TextFormat return their exact retained schema representation. Programmatically-built models are encoded from the shared runtime graph.

Source

pub fn make_graph_authoritative(&mut self)

Discard the retained source protobuf and make the mutable runtime graph authoritative for future serialization.

Full-spec fields that are not represented by the execution IR (such as training information and local function declarations) cannot survive this transition.

Source

pub fn to_text(&self) -> String

Render this model as a human-readable textual dump (ONNX_RS §5).

Source

pub fn to_text_with(&self, opts: &PrintOptions) -> String

Render this model as text with explicit PrintOptions (ONNX_RS §5.4).

Source

pub fn from_text(source: &str) -> Result<Self>

Parse a model previously rendered in the textual format (ONNX_RS §5.4).

Source

pub fn validate(&self) -> ValidationResult

Validate this model with the default OnnxChecker (ONNX_RS §8).

Auto Trait Implementations§

§

impl Freeze for Model

§

impl RefUnwindSafe for Model

§

impl Send for Model

§

impl Sync for Model

§

impl Unpin for Model

§

impl UnsafeUnpin for Model

§

impl UnwindSafe for Model

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.