Class OrtSession
- All Implemented Interfaces:
AutoCloseable
Allows the inspection of the model's input and output nodes. Produced by an OrtEnvironment.
Most instance methods throw IllegalStateException if the session is closed and the
methods are called.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic classUsed to control logging and termination of a call torun(java.util.Map<java.lang.String, ? extends ai.onnxruntime.OnnxTensorLike>).static classRepresents the options used to construct this session. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the session, releasing it's resources.Ends the profiling session and returns the output of the profiler.Returns the info objects for the inputs, including their names and types.Returns the input names.Gets the metadata for the currently loaded model.longReturns the number of inputs this model expects.longReturns the number of outputs this model expects.Returns the info objects for the outputs, including their names and types.Returns the output names.longReturns the timestamp that profiling started in nanoseconds.run(Map<String, ? extends OnnxTensorLike> inputs) Scores an input feed dict, returning the map of all inferred outputs.run(Map<String, ? extends OnnxTensorLike> inputs, OrtSession.RunOptions runOptions) Scores an input feed dict, returning the map of all inferred outputs.Scores an input feed dict, returning the map of pinned outputs.Scores an input feed dict, returning the map of requested inferred outputs.run(Map<String, ? extends OnnxTensorLike> inputs, Set<String> requestedOutputs, OrtSession.RunOptions runOptions) Scores an input feed dict, returning the map of requested inferred outputs.run(Map<String, ? extends OnnxTensorLike> inputs, Set<String> requestedOutputs, Map<String, ? extends OnnxValue> pinnedOutputs) Scores an input feed dict, returning the map of requested and pinned outputs.run(Map<String, ? extends OnnxTensorLike> inputs, Set<String> requestedOutputs, Map<String, ? extends OnnxValue> pinnedOutputs, OrtSession.RunOptions runOptions) Scores an input feed dict, returning the map of requested and pinned outputs.toString()
-
Method Details
-
getNumInputs
public long getNumInputs()Returns the number of inputs this model expects.- Returns:
- The number of inputs.
-
getNumOutputs
public long getNumOutputs()Returns the number of outputs this model expects.- Returns:
- The number of outputs.
-
getInputNames
Returns the input names. The underlying collection is sorted based on the input id number.- Returns:
- The input names.
-
getOutputNames
Returns the output names. The underlying collection is sorted based on the output id number.- Returns:
- The output names.
-
getInputInfo
Returns the info objects for the inputs, including their names and types. The underlying collection is sorted based on the input id number.- Returns:
- The input information.
- Throws:
OrtException- If there was an error in native code.
-
getOutputInfo
Returns the info objects for the outputs, including their names and types. The underlying collection is sorted based on the output id number.- Returns:
- The output information.
- Throws:
OrtException- If there was an error in native code.
-
run
Scores an input feed dict, returning the map of all inferred outputs.The outputs are sorted based on their id number.
- Parameters:
inputs- The inputs to score.- Returns:
- The inferred outputs.
- Throws:
OrtException- If there was an error in native code, the input names are invalid, or if there are zero or too many inputs.
-
run
public OrtSession.Result run(Map<String, ? extends OnnxTensorLike> inputs, OrtSession.RunOptions runOptions) throws OrtExceptionScores an input feed dict, returning the map of all inferred outputs.The outputs are sorted based on their id number.
- Parameters:
inputs- The inputs to score.runOptions- The RunOptions to control this run.- Returns:
- The inferred outputs.
- Throws:
OrtException- If there was an error in native code, the input names are invalid, or if there are zero or too many inputs.
-
run
public OrtSession.Result run(Map<String, ? extends OnnxTensorLike> inputs, Set<String> requestedOutputs) throws OrtExceptionScores an input feed dict, returning the map of requested inferred outputs.The outputs are sorted based on the supplied set traversal order.
- Parameters:
inputs- The inputs to score.requestedOutputs- The requested outputs.- Returns:
- The inferred outputs.
- Throws:
OrtException- If there was an error in native code, the input or output names are invalid, or if there are zero or too many inputs or outputs.
-
run
public OrtSession.Result run(Map<String, ? extends OnnxTensorLike> inputs, Set<String> requestedOutputs, OrtSession.RunOptions runOptions) throws OrtExceptionScores an input feed dict, returning the map of requested inferred outputs.The outputs are sorted based on the supplied set traversal order.
- Parameters:
inputs- The inputs to score.requestedOutputs- The requested outputs.runOptions- The RunOptions to control this run.- Returns:
- The inferred outputs.
- Throws:
OrtException- If there was an error in native code, the input or output names are invalid, or if there are zero or too many inputs or outputs.
-
run
public OrtSession.Result run(Map<String, ? extends OnnxTensorLike> inputs, Map<String, throws OrtException? extends OnnxValue> pinnedOutputs) Scores an input feed dict, returning the map of pinned outputs.The outputs are sorted based on the supplied map traversal order.
Note: pinned outputs are not owned by the
OrtSession.Resultobject, and are not closed when the result object is closed.- Parameters:
inputs- The inputs to score.pinnedOutputs- The requested outputs which the user has allocated.- Returns:
- The inferred outputs.
- Throws:
OrtException- If there was an error in native code, the input or output names are invalid, or if there are zero or too many inputs or outputs.
-
run
public OrtSession.Result run(Map<String, ? extends OnnxTensorLike> inputs, Set<String> requestedOutputs, Map<String, throws OrtException? extends OnnxValue> pinnedOutputs) Scores an input feed dict, returning the map of requested and pinned outputs.The outputs are sorted based on the supplied set traversal order with pinned outputs first, then requested outputs. An
IllegalArgumentExceptionis thrown if the same output name appears in both the requested outputs and the pinned outputs.Note: pinned outputs are not owned by the
OrtSession.Resultobject, and are not closed when the result object is closed.- Parameters:
inputs- The inputs to score.requestedOutputs- The requested outputs which ORT will allocate.pinnedOutputs- The requested outputs which the user has allocated.- Returns:
- The inferred outputs.
- Throws:
OrtException- If there was an error in native code, the input or output names are invalid, or if there are zero or too many inputs or outputs.
-
run
public OrtSession.Result run(Map<String, ? extends OnnxTensorLike> inputs, Set<String> requestedOutputs, Map<String, throws OrtException? extends OnnxValue> pinnedOutputs, OrtSession.RunOptions runOptions) Scores an input feed dict, returning the map of requested and pinned outputs.The outputs are sorted based on the supplied set traversal order with pinned outputs first, then requested outputs. An
IllegalArgumentExceptionis thrown if the same output name appears in both the requested outputs and the pinned outputs.Note: pinned outputs are not owned by the
OrtSession.Resultobject, and are not closed when the result object is closed.- Parameters:
inputs- The inputs to score.requestedOutputs- The requested outputs which ORT will allocate.pinnedOutputs- The requested outputs which the user has allocated.runOptions- The RunOptions to control this run.- Returns:
- The inferred outputs.
- Throws:
OrtException- If there was an error in native code, the input or output names are invalid, or if there are zero or too many inputs or outputs.
-
getMetadata
Gets the metadata for the currently loaded model.- Returns:
- The metadata.
- Throws:
OrtException- If the native call failed.
-
getProfilingStartTimeInNs
Returns the timestamp that profiling started in nanoseconds.- Returns:
- the profiling start time in ns.
- Throws:
OrtException- If the native call failed.
-
endProfiling
Ends the profiling session and returns the output of the profiler.Profiling should be enabled in the
OrtSession.SessionOptionsused to construct thisSession.- Returns:
- The profiling output.
- Throws:
OrtException- If the native call failed.
-
toString
-
close
Closes the session, releasing it's resources.- Specified by:
closein interfaceAutoCloseable- Throws:
OrtException- If it failed to close.
-