Skip to main content

Interpreter

Struct Interpreter 

Source
pub struct Interpreter<'lib> { /* private fields */ }
Expand description

TFLite inference engine.

Owns its delegates and provides access to input/output tensors. Created via Interpreter::builder.

Implementations§

Source§

impl<'lib> Interpreter<'lib>

Source

pub fn builder(lib: &'lib Library) -> Result<InterpreterBuilder<'lib>>

Create a new InterpreterBuilder for configuring an interpreter.

§Errors

Returns an error if TfLiteInterpreterOptionsCreate returns null.

Source

pub fn allocate_tensors(&mut self) -> Result<()>

Re-allocate tensors after an input resize.

This must be called after Interpreter::resize_input and before Interpreter::invoke. Any previously obtained tensor slices or pointers are invalidated.

§Errors

Returns an error if the C API returns a non-OK status.

Source

pub fn resize_input(&mut self, input_index: usize, shape: &[i32]) -> Result<()>

Resize an input tensor’s dimensions.

After resizing, Interpreter::allocate_tensors must be called before inference can proceed.

§Errors

Returns an error if the C API returns a non-OK status (e.g., the input index is out of range).

Source

pub fn invoke(&mut self) -> Result<()>

Run model inference.

§Errors

Returns an error if the C API returns a non-OK status.

Source

pub fn inputs(&self) -> Result<Vec<Tensor<'_>>>

Get immutable views of all input tensors.

§Errors

Returns an error if any input tensor pointer is null.

Source

pub fn inputs_mut(&mut self) -> Result<Vec<TensorMut<'_>>>

Get mutable views of all input tensors.

§Errors

Returns an error if any input tensor pointer is null.

Source

pub fn outputs(&self) -> Result<Vec<Tensor<'_>>>

Get immutable views of all output tensors.

§Errors

Returns an error if any output tensor pointer is null.

Source

pub fn input_count(&self) -> usize

Returns the number of input tensors.

Source

pub fn output_count(&self) -> usize

Returns the number of output tensors.

Source

pub fn delegates(&self) -> &[Delegate]

Access all delegates owned by this interpreter.

Source

pub fn delegate(&self, index: usize) -> Option<&Delegate>

Access a specific delegate by index.

Trait Implementations§

Source§

impl Debug for Interpreter<'_>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for Interpreter<'_>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'lib> Freeze for Interpreter<'lib>

§

impl<'lib> !RefUnwindSafe for Interpreter<'lib>

§

impl<'lib> !Send for Interpreter<'lib>

§

impl<'lib> !Sync for Interpreter<'lib>

§

impl<'lib> Unpin for Interpreter<'lib>

§

impl<'lib> UnsafeUnpin for Interpreter<'lib>

§

impl<'lib> !UnwindSafe for Interpreter<'lib>

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> 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, 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.