Struct Graph

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

Graph builder.

Implementations§

Source§

impl Graph

Source

pub fn new<S: Into<String>>(name: S) -> Self

Creates a new builder.

Examples found in repository?
examples/mean_reverse.rs (line 5)
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 5)
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 5)
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 5)
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 5)
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}
Source

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

Sets graph name.

Source

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

Sets graph doc_string.

Source

pub fn constant<S: Into<String>, T: Into<TensorProto>>( &mut self, name: S, tensor: T, ) -> Node

Creates constant node in a graph.

Examples found in repository?
examples/ensemble.rs (line 17)
16fn stddev(graph: &mut builder::Graph, x: &Node) -> Node {
17    let two = graph.constant("two", 2.0f32);
18    (x - x.mean(1, true)).abs().pow(two).mean(1, true).sqrt()
19}
20
21fn mean_reverse(graph: &mut builder::Graph, x: &Node) -> Node {
22    let two = graph.constant("two", 2.0f32);
23    -(x - x.mean(1, true)) * two + x
24}
More examples
Hide additional examples
examples/mean_reverse.rs (line 7)
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}
examples/stddev.rs (line 7)
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/concat.rs (line 7)
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}
Source

pub fn concat<I>(&mut self, axis: i64, inputs: I) -> Node
where I: IntoIterator, I::Item: Into<String>,

Creates a concat node in a graph.

Examples found in repository?
examples/concat.rs (line 9)
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}
Source

pub fn nodes<T: Into<NodeProto>>(self, node: T) -> Self

Inserts graph nodes.

Source

pub fn inputs<T: Into<ValueInfoProto>>(self, input: T) -> Self

Inserts graph inputs.

Source

pub fn outputs<T: Into<ValueInfoProto>>(self, output: T) -> Self

Inserts graph outputs.

Examples found in repository?
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}
Source

pub fn outputs_typed<T: Into<ValueInfoProto>, D: Into<TypeProto>>( self, output: T, typ: D, ) -> Self

Inserts typed graph outputs.

Examples found in repository?
examples/mean_reverse.rs (line 9)
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 9)
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/concat.rs (line 10)
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 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 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}
Source

pub fn initializer<T: Into<TensorProto>>(self, initializer: T) -> Self

Inserts graph initializers.

Source

pub fn node<T: Into<String>>(&mut self, name: T) -> Node

Creates graph node builder.

Source

pub fn input<T: Into<String>>(&mut self, name: T) -> Value

Creates graph input builder.

Examples found in repository?
examples/mean_reverse.rs (line 6)
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 6)
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 8)
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 6)
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 6)
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}
Source

pub fn output<T: Into<String>>(&mut self, name: T) -> Value

Creates graph output builder.

Source

pub fn model(self) -> Model

Builds a model builder from graph.

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}
Source

pub fn build(self) -> GraphProto

Builds the graph.

Trait Implementations§

Source§

impl Clone for Graph

Source§

fn clone(&self) -> Graph

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 Graph

Source§

fn default() -> Graph

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

impl Into<GraphProto> for Graph

Source§

fn into(self) -> GraphProto

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

Auto Trait Implementations§

§

impl Freeze for Graph

§

impl !RefUnwindSafe for Graph

§

impl !Send for Graph

§

impl !Sync for Graph

§

impl Unpin for Graph

§

impl !UnwindSafe for Graph

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.