pub struct MlModel { /* private fields */ }Expand description
Loaded and optimised ONNX model for corner refinement.
The model accepts a batch of f32 intensity patches with shape
[N, 1, patch_size, patch_size] (values in [0, 1]) and returns
[N, 3] with columns [dx, dy, conf_logit]. Only dx and dy
are currently used; conf_logit is ignored.
Implementations§
Source§impl MlModel
impl MlModel
Sourcepub fn load(source: ModelSource) -> Result<Self>
pub fn load(source: ModelSource) -> Result<Self>
Load and optimise an ONNX model from the given source.
For ModelSource::EmbeddedDefault the embed-model Cargo
feature must be enabled; an error is returned otherwise.
§Errors
Returns an error if the model file cannot be read, the ONNX graph is malformed, or tract optimisation / compilation fails.
Sourcepub fn patch_size(&self) -> usize
pub fn patch_size(&self) -> usize
Side length (in pixels) of the square intensity patch the model expects.
Sourcepub fn infer_batch(
&self,
patches: &[f32],
batch: usize,
) -> Result<Vec<[f32; 3]>>
pub fn infer_batch( &self, patches: &[f32], batch: usize, ) -> Result<Vec<[f32; 3]>>
Run inference on a flat batch of intensity patches.
patches must contain exactly batch * patch_size * patch_size
f32 values in [N, 1, H, W] order (values in [0, 1]).
Returns one [dx, dy, conf_logit] triple per input patch.
§Errors
Returns an error if the slice length does not match
batch * patch_size², if the ONNX output shape is unexpected,
or if tract inference fails.
Auto Trait Implementations§
impl Freeze for MlModel
impl !RefUnwindSafe for MlModel
impl Send for MlModel
impl Sync for MlModel
impl Unpin for MlModel
impl UnsafeUnpin for MlModel
impl !UnwindSafe for MlModel
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>. Box<dyn Any> can
then be further downcast into Box<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>. Rc<Any> 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> 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