Class OnnxModel
Object
OnnxModel
- All Implemented Interfaces:
AutoCloseable
,ImageInferenceModel<ai.onnxruntime.OnnxTensor>
,InferenceModel
A model that can be used for inference using the ONNX
Runtime's Java API.
Note that a temporary directory is created by the ONNX Runtime, something ala
C:\Users\owen\AppData\Local\Temp\onnxruntime-java3819764023069624084
with the final number
changing. This should be deleted after the Java VM closes, but this doesn't seem to always
happen. This requires further investigation, but can cause up a large buildup of files, as each
instance is approximately 300MBs.
- Author:
- Owen Feehan
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Indicates that the model will no longer be used, and does appropriate tidying up and freeing of resources.<S> S
performInference
(ai.onnxruntime.OnnxTensor input, String inputName, List<String> outputNames, CheckedFunction<List<ai.onnxruntime.OnnxTensor>, S, OperationFailedException> convertFunction) Performs inference on a single-input, to create an output.
-
Constructor Details
-
OnnxModel
public OnnxModel(ai.onnxruntime.OrtSession session)
-
-
Method Details
-
performInference
public <S> S performInference(ai.onnxruntime.OnnxTensor input, String inputName, List<String> outputNames, CheckedFunction<List<ai.onnxruntime.OnnxTensor>, S, throws OperationFailedExceptionOperationFailedException> convertFunction) Description copied from interface:ImageInferenceModel
Performs inference on a single-input, to create an output.- Specified by:
performInference
in interfaceImageInferenceModel<ai.onnxruntime.OnnxTensor>
- Type Parameters:
S
- the data-type the output is exposed as.- Parameters:
input
- the input for inference.inputName
- the name associated withinput
in the model.outputNames
-convertFunction
- converts the output to type<S>
.- Returns:
- the converted output.
- Throws:
OperationFailedException
- if the inference cannot successfully complete.
-
close
Description copied from interface:InferenceModel
Indicates that the model will no longer be used, and does appropriate tidying up and freeing of resources.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceInferenceModel
- Throws:
OperationFailedException
-