Package ai.onnxruntime
package ai.onnxruntime
A Java interface to the ONNX Runtime.
Provides access to the same execution backends as the C library. Non-representable types in Java (such as fp16) are converted into the nearest Java primitive type when accessed through this API.
There are two shared libraries required: onnxruntime and onnxruntime4j_jni
. The loader is in OnnxRuntime and the logic is in this order:
- The user may signal to skip loading of a shared library using a property in the form
onnxruntime.native.LIB_NAME.skipwith a value oftrue. This means the user has decided to load the library by some other means. - The user may specify an explicit location of all native library files using a property in
the form
onnxruntime.native.path. This usesSystem.load(java.lang.String). - The user may specify an explicit location of the shared library file using a property in
the form
onnxruntime.native.LIB_NAME.path. This usesSystem.load(java.lang.String). - The shared library is autodiscovered:
- If the shared library is present in the classpath resources, load using
System.load(java.lang.String)via a temporary file. Ideally, this should be the default use case when adding JAR's/dependencies containing the shared libraries to your classpath. - If the shared library is not present in the classpath resources, then load using
System.loadLibrary(java.lang.String), which usually looks elsewhere on the filesystem for the library. The semantics and behavior of that method are system/JVM dependent. Typically, thejava.library.pathproperty is used to specify the location of native libraries.
- If the shared library is present in the classpath resources, load using
Note that CUDA, ROCM, DNNL, OpenVINO and TensorRT are all "shared library execution providers" and must be stored either in the directory containing the ONNX Runtime core native library, or as a classpath resource. This is because these providers are loaded by the ONNX Runtime native library itself and the Java API cannot control the loading location.
-
ClassDescriptionDescribes an
OnnxMapobject or output node.The info for an input or output node from an ONNX model.An enum representing ONNX Runtime supported Java primitive types (and String).A container for a map returned byOrtSession.run(Map).An enum representing the Java type of the values stored in anOnnxMap.Contains the metadata associated with an ONNX model.A sequence ofOnnxValues all of the same type.A Java object wrapping an OnnxSparseTensor.The Java side representation of a block sparse tensor.The Java side representation of a COO sparse tensor.The Java side representation of a CSRC sparse tensor.OnnxSparseTensor.SparseTensor<T extends Buffer>Abstract base class for Java sparse tensorsThe type of the sparse tensor.A Java object wrapping an OnnxTensor.Currently implemented byOnnxTensor,OnnxSparseTensor.Top interface for input and output values from ONNX models.The type of theOnnxValue, mirroring the id in the C API.The host object for the ONNX Runtime system.Controls the global thread pools in the environment.An exception which contains the error message and code produced by the native onnxruntime.Maps theOrtErrorCodestruct inonnxruntime_c_api.hwith an additional entry for Java side errors.The logging severity level.A container for an adapter which can be supplied toOrtSession.RunOptions.addActiveLoraAdapter(OrtLoraAdapter)to apply the adapter to a specific execution of a model.The execution providers available through the Java API.An abstract base class for execution provider options classes.Functional interface mirroring a Java supplier, but can throw OrtException.Wraps an ONNX model and allows inference calls.Used to control logging and termination of a call toOrtSession.run(java.util.Map<java.lang.String, ? extends ai.onnxruntime.OnnxTensorLike>).Represents the options used to construct this session.The execution mode to use.The optimisation level to use.Wraps an ONNX training model and allows training and inference calls.Util code for interacting with Java arrays.Describes anOnnxSequence, including it's element type if known.Describes anOnnxTensor, including it's size, shape and element type.The native element types supported by the ONNX runtime.Interface for info objects describing anOnnxValue.