Package com.itextpdf.pdfocr.onnxtr
Class AbstractOnnxPredictorR>
java.lang.Object
com.itextpdf.pdfocr.onnxtr.AbstractOnnxPredictorR>
- Type Parameters:
-
T
- predictor input type -
R
- predictor output type
- All Implemented Interfaces:
-
IPredictor
,R> AutoCloseable
- Direct Known Subclasses:
-
OnnxDetectionPredictor
,OnnxOrientationPredictor
,OnnxRecognitionPredictor
Abstract predictor, based on models running over ONNX runtime.
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
AbstractOnnxPredictor
(String modelPath, OnnxInputProperties inputProperties, long[] outputShape) Creates a new abstract predictor. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
fromOutputBuffer
(List<T> inputBatch, FloatBufferMdArray outputBatch) Converts ONNX runtime model batched output MD-array buffer to a list of predictor outputs.Performs prediction on a sequence of input items.protected abstract FloatBufferMdArray
toInputBuffer
(List<T> batch) Converts predictor inputs to an ONNX runtime model batched input MD-array buffer.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.itextpdf.pdfocr.onnxtr.IPredictor
predict
-
Constructor Details
-
AbstractOnnxPredictor
protected AbstractOnnxPredictor(String modelPath, OnnxInputProperties inputProperties, long[] outputShape) Creates a new abstract predictor.If the specified model does not match input and output properties, it will throw an exception.
- Parameters:
-
modelPath
- path to the ONNX runtime model to load -
inputProperties
- expected input properties of a model -
outputShape
- expected shape of the output. -1 entries mean that the dimension can be of any size (ex. batch size)
-
-
Method Details
-
predict
-
close
public void close()- Specified by:
-
close
in interfaceAutoCloseable
-
toInputBuffer
Converts predictor inputs to an ONNX runtime model batched input MD-array buffer.- Parameters:
-
batch
- batch of raw predictor inputs - Returns:
- batched model input MD-array buffer
-
fromOutputBuffer
Converts ONNX runtime model batched output MD-array buffer to a list of predictor outputs.- Parameters:
-
inputBatch
- list of raw predictor inputs, matching the output -
outputBatch
- batched model output MD-array buffer - Returns:
- a list of predictor output
-