pub struct OnnxModel {
model: InferenceModel,
}Expand description
A parsed ONNX model, ready to run at any spatial size.
The graph is kept in tract’s shape-inferring form and specialized to the
concrete input shapes on each run call, so one instance
serves volumes of different dimensions (fully-convolutional nets).
Fields§
§model: InferenceModelImplementations§
Source§impl OnnxModel
impl OnnxModel
Sourcepub fn load(bytes: &[u8]) -> Result<Self, OnnxError>
pub fn load(bytes: &[u8]) -> Result<Self, OnnxError>
Parse an ONNX model from its serialized bytes.
Sourcepub fn run(&self, inputs: &[Tensor]) -> Result<Vec<Tensor>, OnnxError>
pub fn run(&self, inputs: &[Tensor]) -> Result<Vec<Tensor>, OnnxError>
Run the model with inputs bound to graph inputs in order; returns every
graph output as an f32 Tensor.
Sourcepub fn run_single(&self, input: &Tensor) -> Result<Tensor, OnnxError>
pub fn run_single(&self, input: &Tensor) -> Result<Tensor, OnnxError>
Convenience for single-input / single-output nets.
Sourcepub fn plan_for(&self, input_shapes: &[&[usize]]) -> Result<OnnxPlan, OnnxError>
pub fn plan_for(&self, input_shapes: &[&[usize]]) -> Result<OnnxPlan, OnnxError>
Compile a reusable execution plan specialized to fixed input shapes.
run re-clones and re-optimizes the whole graph on every call — fine for
one-shot whole-volume inference, but wasteful when running many equal-shaped tensors
(e.g. every patch of a tiled inversion). Build one OnnxPlan for the patch shape and
reuse it: tract’s optimizer (into_optimized — constant-folding conv weights, operator
fusion, plan building) then runs exactly once instead of per patch.
Auto Trait Implementations§
impl !RefUnwindSafe for OnnxModel
impl !UnwindSafe for OnnxModel
impl Freeze for OnnxModel
impl Send for OnnxModel
impl Sync for OnnxModel
impl Unpin for OnnxModel
impl UnsafeUnpin for OnnxModel
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> DowncastSend for T
impl<T> DowncastSend for T
§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more