Class OnnxModel

Object
org.anchoranalysis.plugin.onnx.model.OnnxModel
All Implemented Interfaces:
AutoCloseable, org.anchoranalysis.image.inference.ImageInferenceModel<ai.onnxruntime.OnnxTensor>, org.anchoranalysis.inference.InferenceModel

public class OnnxModel
extends Object
implements org.anchoranalysis.image.inference.ImageInferenceModel<ai.onnxruntime.OnnxTensor>
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 
    Constructor Description
    OnnxModel​(ai.onnxruntime.OrtSession session)  
  • Method Summary

    Modifier and Type Method Description
    void close()  
    <S> S performInference​(ai.onnxruntime.OnnxTensor input, String inputName, List<String> outputNames, org.anchoranalysis.core.functional.checked.CheckedFunction<List<ai.onnxruntime.OnnxTensor>,​S,​org.anchoranalysis.core.exception.OperationFailedException> convertFunction)  

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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, org.anchoranalysis.core.functional.checked.CheckedFunction<List<ai.onnxruntime.OnnxTensor>,​S,​org.anchoranalysis.core.exception.OperationFailedException> convertFunction) throws org.anchoranalysis.core.exception.OperationFailedException
      Specified by:
      performInference in interface org.anchoranalysis.image.inference.ImageInferenceModel<ai.onnxruntime.OnnxTensor>
      Throws:
      org.anchoranalysis.core.exception.OperationFailedException
    • close

      public void close() throws org.anchoranalysis.core.exception.OperationFailedException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface org.anchoranalysis.inference.InferenceModel
      Throws:
      org.anchoranalysis.core.exception.OperationFailedException