Struct Model

Source
pub struct Model { /* private fields */ }
Expand description

Model builder.

Implementations§

Source§

impl Model

Source

pub fn new<G: Into<GraphProto>>(graph: G) -> Self

Creates a new builder.

Source

pub fn domain<S: Into<String>>(self, domain: S) -> Self

Sets model doc_string.

Source

pub fn model_version(self, model_version: i64) -> Self

Sets model doc_string.

Source

pub fn producer_name<S: Into<String>>(self, producer_name: S) -> Self

Sets model doc_string.

Source

pub fn producer_version<S: Into<String>>(self, producer_version: S) -> Self

Sets model doc_string.

Source

pub fn doc_string<S: Into<String>>(self, doc_string: S) -> Self

Sets model doc_string.

Source

pub fn metadata<K: Into<String>, V: Into<String>>( self, key: K, value: V, ) -> Self

Inserts model metadata.

Source

pub fn opset_import(self, opset: OperatorSetIdProto) -> Self

Inserts operator set import.

Source

pub fn build(self) -> ModelProto

Builds the model.

Examples found in repository?
examples/mean_reverse.rs (line 10)
4fn main() {
5    let mut graph = builder::Graph::new("reverse");
6    let x = graph.input("X").typed(DataType::Float).dim(1).dim(6).node();
7    let two = graph.constant("two", 2.0f32);
8    let out = -(&x - x.mean(1, true)) * two + x;
9    let graph = graph.outputs_typed(out, DataType::Float);
10    let model = graph.model().build();
11    save_model("mean-reverse.onnx", &model).unwrap();
12}
More examples
Hide additional examples
examples/stddev.rs (line 10)
4fn main() {
5    let mut graph = builder::Graph::new("stddev");
6    let x = graph.input("X").typed(DataType::Float).dim(1).dim(6).node();
7    let two = graph.constant("two", 2.0f32);
8    let std = (&x - x.mean(1, true)).abs().pow(two).mean(1, true).sqrt();
9    let graph = graph.outputs_typed(std.with_name("stddev"), DataType::Float);
10    let model = graph.model().build();
11    save_model("stddev.onnx", &model).unwrap();
12}
examples/add.rs (line 22)
4fn main() {
5    let mut graph = builder::Graph::new("add");
6
7    let x = graph
8        .input("X")
9        .typed(DataType::Float)
10        .dim(1)
11        .dim(10)
12        .node();
13    let y = graph
14        .input("Y")
15        .typed(DataType::Float)
16        .dim(1)
17        .dim(10)
18        .node();
19
20    let z = (x + y).with_name("Z");
21
22    let model = graph.outputs(z).model().build();
23
24    save_model("add.onnx", &model).unwrap();
25}
examples/concat.rs (line 11)
4fn main() {
5    let mut graph = builder::Graph::new("concat");
6    let x = graph.input("X").typed(DataType::Float).dim(1).dim(6).node();
7    let two = graph.constant("two", 2.0f32);
8    let mean_reverse = -(&x - x.mean(1, true)) * two + &x;
9    let concat = graph.concat(0, vec![x, mean_reverse]).with_name("concat");
10    let graph = graph.outputs_typed(concat, DataType::Float);
11    let model = graph.model().build();
12    save_model("concat.onnx", &model).unwrap();
13}
examples/ensemble.rs (line 12)
4fn main() {
5    let mut graph = builder::Graph::new("stddev");
6    let x = graph.input("X").typed(DataType::Float).dim(1).dim(6).node();
7    let std = stddev(&mut graph, &x);
8    let mrev = mean_reverse(&mut graph, &x);
9    let graph = graph
10        .outputs_typed(std.with_name("stddev"), DataType::Float)
11        .outputs_typed(mrev.with_name("mean_reverse"), DataType::Float);
12    let model = graph.model().build();
13    save_model("ensemble.onnx", &model).unwrap();
14}

Trait Implementations§

Source§

impl Clone for Model

Source§

fn clone(&self) -> Model

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for Model

Source§

fn default() -> Model

Returns the “default value” for a type. Read more
Source§

impl Into<ModelProto> for Model

Source§

fn into(self) -> ModelProto

Converts this type into the (usually inferred) input type.

Auto Trait Implementations§

§

impl Freeze for Model

§

impl RefUnwindSafe for Model

§

impl Send for Model

§

impl Sync for Model

§

impl Unpin 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.