Package ai.onnxruntime
Class OrtSession
- java.lang.Object
-
- ai.onnxruntime.OrtSession
-
- All Implemented Interfaces:
java.lang.AutoCloseable
public class OrtSession extends java.lang.Object implements java.lang.AutoCloseableWraps an ONNX model and allows inference calls.Allows the inspection of the model's input and output nodes. Produced by an
OrtEnvironment.Most instance methods throw
IllegalStateExceptionif the session is closed and the methods are called.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classOrtSession.Resultstatic classOrtSession.RunOptionsUsed to control logging and termination of a call torun(java.util.Map<java.lang.String, ai.onnxruntime.OnnxTensor>).static classOrtSession.SessionOptionsRepresents the options used to construct this session.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes the session, releasing it's resources.java.lang.StringendProfiling()Ends the profiling session and returns the output of the profiler.java.util.Map<java.lang.String,NodeInfo>getInputInfo()Returns the info objects for the inputs, including their names and types.java.util.Set<java.lang.String>getInputNames()Returns the input names.OnnxModelMetadatagetMetadata()Gets the metadata for the currently loaded model.longgetNumInputs()Returns the number of inputs this model expects.longgetNumOutputs()Returns the number of outputs this model expects.java.util.Map<java.lang.String,NodeInfo>getOutputInfo()Returns the info objects for the outputs, including their names and types.java.util.Set<java.lang.String>getOutputNames()Returns the output names.longgetProfilingStartTimeInNs()Returns the timestamp that profiling started in nanoseconds.OrtSession.Resultrun(java.util.Map<java.lang.String,OnnxTensor> inputs)Scores an input feed dict, returning the map of all inferred outputs.OrtSession.Resultrun(java.util.Map<java.lang.String,OnnxTensor> inputs, OrtSession.RunOptions runOptions)Scores an input feed dict, returning the map of all inferred outputs.OrtSession.Resultrun(java.util.Map<java.lang.String,OnnxTensor> inputs, java.util.Set<java.lang.String> requestedOutputs)Scores an input feed dict, returning the map of requested inferred outputs.OrtSession.Resultrun(java.util.Map<java.lang.String,OnnxTensor> inputs, java.util.Set<java.lang.String> requestedOutputs, OrtSession.RunOptions runOptions)Scores an input feed dict, returning the map of requested inferred outputs.java.lang.StringtoString()
-
-
-
Method Detail
-
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
public java.util.Set<java.lang.String> getInputNames()
Returns the input names. The underlying collection is sorted based on the input id number.- Returns:
- The input names.
-
getOutputNames
public java.util.Set<java.lang.String> getOutputNames()
Returns the output names. The underlying collection is sorted based on the output id number.- Returns:
- The output names.
-
getInputInfo
public java.util.Map<java.lang.String,NodeInfo> getInputInfo() throws OrtException
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
public java.util.Map<java.lang.String,NodeInfo> getOutputInfo() throws OrtException
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
public OrtSession.Result run(java.util.Map<java.lang.String,OnnxTensor> inputs) throws OrtException
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(java.util.Map<java.lang.String,OnnxTensor> inputs, OrtSession.RunOptions runOptions) throws OrtException
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.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(java.util.Map<java.lang.String,OnnxTensor> inputs, java.util.Set<java.lang.String> requestedOutputs) throws OrtException
Scores 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(java.util.Map<java.lang.String,OnnxTensor> inputs, java.util.Set<java.lang.String> requestedOutputs, OrtSession.RunOptions runOptions) throws OrtException
Scores an input feed dict, returning the map of requested inferred outputs.The outputs are sorted based on the supplied set traveral 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.
-
getMetadata
public OnnxModelMetadata getMetadata() throws OrtException
Gets the metadata for the currently loaded model.- Returns:
- The metadata.
- Throws:
OrtException- If the native call failed.
-
getProfilingStartTimeInNs
public long getProfilingStartTimeInNs() throws OrtExceptionReturns the timestamp that profiling started in nanoseconds.- Returns:
- the profiling start time in ns.
- Throws:
OrtException- If the native call failed.
-
endProfiling
public java.lang.String endProfiling() throws OrtExceptionEnds 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
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
close
public void close() throws OrtExceptionCloses the session, releasing it's resources.- Specified by:
closein interfacejava.lang.AutoCloseable- Throws:
OrtException- If it failed to close.
-
-