pub struct Session {
pub inputs: Vec<Input>,
pub outputs: Vec<Output>,
/* private fields */
}
Expand description
An ONNX Runtime graph to be used for inference.
let session = Session::builder()?.commit_from_file("tests/data/upsample.onnx")?;
let input = ndarray::Array4::<f32>::zeros((1, 64, 64, 3));
let outputs = session.run(ort::inputs![input]?)?;
Fields§
§inputs: Vec<Input>
Information about the graph’s inputs.
outputs: Vec<Output>
Information about the graph’s outputs.
Implementations§
source§impl Session
impl Session
sourcepub fn builder() -> Result<SessionBuilder>
pub fn builder() -> Result<SessionBuilder>
Creates a new SessionBuilder
.
sourcepub fn create_binding(&self) -> Result<IoBinding<'_>>
pub fn create_binding(&self) -> Result<IoBinding<'_>>
Creates a new IoBinding
for this session.
sourcepub fn ptr(&self) -> *mut OrtSession
pub fn ptr(&self) -> *mut OrtSession
Returns the underlying ort_sys::OrtSession
pointer.
sourcepub fn inner(&self) -> Arc<SharedSessionInner>
pub fn inner(&self) -> Arc<SharedSessionInner>
Get a shared (Arc
’d) reference to the underlying SharedSessionInner
, which holds the
ort_sys::OrtSession
pointer and the session allocator.
sourcepub fn run<'s, 'i, 'v: 'i, const N: usize>(
&'s self,
input_values: impl Into<SessionInputs<'i, 'v, N>>
) -> Result<SessionOutputs<'s>>
pub fn run<'s, 'i, 'v: 'i, const N: usize>( &'s self, input_values: impl Into<SessionInputs<'i, 'v, N>> ) -> Result<SessionOutputs<'s>>
Run input data through the ONNX graph, performing inference.
See crate::inputs!
for a convenient macro which will help you create your session inputs from ndarray
s or
other data. You can also provide a Vec
, array, or HashMap
of Value
s if you create your inputs
dynamically.
let session = Session::builder()?.commit_from_file("tests/data/upsample.onnx")?;
let input = ndarray::Array4::<f32>::zeros((1, 64, 64, 3));
let outputs = session.run(ort::inputs![input]?)?;
sourcepub fn run_with_options<'s, 'i, 'v: 'i, const N: usize>(
&'s self,
input_values: impl Into<SessionInputs<'i, 'v, N>>,
run_options: Arc<RunOptions>
) -> Result<SessionOutputs<'s>>
pub fn run_with_options<'s, 'i, 'v: 'i, const N: usize>( &'s self, input_values: impl Into<SessionInputs<'i, 'v, N>>, run_options: Arc<RunOptions> ) -> Result<SessionOutputs<'s>>
Run input data through the ONNX graph, performing inference, with a RunOptions
struct. The most common usage
of RunOptions
is to allow the session run to be terminated from a different thread.
let run_options = Arc::new(RunOptions::new()?);
let run_options_ = Arc::clone(&run_options);
std::thread::spawn(move || {
let _ = run_options_.terminate();
});
let res = session.run_with_options(ort::inputs![input]?, run_options);
// upon termination, the session will return an `Error::SessionRun` error.`
assert_eq!(
&res.unwrap_err().to_string(),
"Failed to run inference on model: Exiting due to terminate flag being set to true."
);
sourcepub fn run_async<'s, 'i, 'v: 'i + 's, const N: usize>(
&'s self,
input_values: impl Into<SessionInputs<'i, 'v, N>> + 'static
) -> Result<InferenceFut<'s>>
pub fn run_async<'s, 'i, 'v: 'i + 's, const N: usize>( &'s self, input_values: impl Into<SessionInputs<'i, 'v, N>> + 'static ) -> Result<InferenceFut<'s>>
Asynchronously run input data through the ONNX graph, performing inference.
Inference will be performed on a thread in the session’s thread pool. Thus, the session must have been
configured to have multiple intra-op threads; see SessionBuilder::with_intra_threads
.
See crate::inputs!
for a convenient macro which will help you create your session inputs from ndarray
s or
other data. You can also provide a Vec
, array, or HashMap
of Value
s if you create your inputs
dynamically.
let session = Session::builder()?.with_intra_threads(2)?.commit_from_file("tests/data/upsample.onnx")?;
let input = ndarray::Array4::<f32>::zeros((1, 64, 64, 3));
let outputs = session.run_async(ort::inputs![input]?)?.await?;
sourcepub fn metadata(&self) -> Result<ModelMetadata<'_>>
pub fn metadata(&self) -> Result<ModelMetadata<'_>>
Gets the session model metadata. See ModelMetadata
for more info.
sourcepub fn end_profiling(&self) -> Result<String>
pub fn end_profiling(&self) -> Result<String>
Ends profiling for this session.
Note that this must be explicitly called at the end of profiling, otherwise the profiling file will be empty.