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: GraphThe computation graph, in the shared onnx_runtime_ir IR.
metadata: ModelMetadataModel-level metadata not carried by the Graph itself.
Implementations§
Source§impl Model
impl Model
Sourcepub fn new(graph: Graph) -> Self
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.
Sourcepub fn with_metadata(graph: Graph, metadata: ModelMetadata) -> Self
pub fn with_metadata(graph: Graph, metadata: ModelMetadata) -> Self
Wrap a Graph together with explicit model-level metadata.
Sourcepub fn set_weights(&mut self, weights: Arc<WeightStore>)
pub fn set_weights(&mut self, weights: Arc<WeightStore>)
Attach the live weight store backing external initializers.
Sourcepub fn weights(&self) -> Option<&Arc<WeightStore>>
pub fn weights(&self) -> Option<&Arc<WeightStore>>
The live weight store, if this model carries one.
Sourcepub fn from_proto(proto: ModelProto) -> Result<Self>
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.
Sourcepub fn to_proto(&self) -> Result<ModelProto>
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.
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.
Sourcepub fn to_text(&self) -> String
pub fn to_text(&self) -> String
Render this model as a human-readable textual dump (ONNX_RS §5).
Sourcepub fn to_text_with(&self, opts: &PrintOptions) -> String
pub fn to_text_with(&self, opts: &PrintOptions) -> String
Render this model as text with explicit PrintOptions (ONNX_RS §5.4).
Sourcepub fn from_text(source: &str) -> Result<Self>
pub fn from_text(source: &str) -> Result<Self>
Parse a model previously rendered in the textual format (ONNX_RS §5.4).
Sourcepub fn validate(&self) -> ValidationResult
pub fn validate(&self) -> ValidationResult
Validate this model with the default OnnxChecker (ONNX_RS §8).