Struct SessionBuilder

Source
pub struct SessionBuilder<'a> { /* private fields */ }
Expand description

Type used to create a session using the builder pattern

A SessionBuilder is created by calling the Environment::new_session_builder() method on the environment.

Once created, use the different methods to configure the session.

Once configured, use the SessionBuilder::with_model_from_file() method to “commit” the builder configuration into a Session.

§Example

let environment = Environment::builder()
    .with_name("test")
    .with_log_level(LoggingLevel::Verbose)
    .build()?;
let mut session = environment
    .new_session_builder()?
    .with_optimization_level(GraphOptimizationLevel::Basic)?
    .with_number_threads(1)?
    .with_model_from_file("squeezenet.onnx")?;

Implementations§

Source§

impl<'a> SessionBuilder<'a>

Source

pub fn with_number_threads(self, num_threads: i16) -> Result<SessionBuilder<'a>>

Configure the session to use a number of threads

Source

pub fn with_optimization_level( self, opt_level: GraphOptimizationLevel, ) -> Result<SessionBuilder<'a>>

Set the session’s optimization level

Source

pub fn with_allocator( self, allocator: AllocatorType, ) -> Result<SessionBuilder<'a>>

Set the session’s allocator

Defaults to AllocatorType::Arena

Source

pub fn with_memory_type( self, memory_type: MemType, ) -> Result<SessionBuilder<'a>>

Set the session’s memory type

Defaults to MemType::Default

Source

pub fn with_model_downloaded<M>(self, model: M) -> Result<Session<'a>>

Download an ONNX pre-trained model from the ONNX Model Zoo and commit the session

Source

pub fn with_model_from_file<P>( self, model_filepath_ref: P, ) -> Result<Session<'a>>
where P: AsRef<Path> + 'a,

Load an ONNX graph from a file and commit the session

Source

pub fn with_model_from_memory<B>(self, model_bytes: B) -> Result<Session<'a>>
where B: AsRef<[u8]>,

Load an ONNX graph from memory and commit the session

Trait Implementations§

Source§

impl<'a> Debug for SessionBuilder<'a>

Source§

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

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

impl<'a> Drop for SessionBuilder<'a>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for SessionBuilder<'a>

§

impl<'a> RefUnwindSafe for SessionBuilder<'a>

§

impl<'a> !Send for SessionBuilder<'a>

§

impl<'a> !Sync for SessionBuilder<'a>

§

impl<'a> Unpin for SessionBuilder<'a>

§

impl<'a> UnwindSafe for SessionBuilder<'a>

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.