Class AbstractOnnxPredictorR>

java.lang.Object
com.itextpdf.pdfocr.onnxtr.AbstractOnnxPredictorR>
Type Parameters:
T - predictor input type
R - predictor output type
All Implemented Interfaces:
IPredictorR>, AutoCloseable
Direct Known Subclasses:
OnnxDetectionPredictor, OnnxOrientationPredictor, OnnxRecognitionPredictor

public abstract class AbstractOnnxPredictorR> extends Object implements IPredictorR>
Abstract predictor, based on models running over ONNX runtime.
  • 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

      public Iterator<R> predict (Iterator<T> inputs)
      Performs prediction on a sequence of input items.

      This method consumes the provided Iterator of inputs and produces an Iterator of outputs, typically yielding one result per input item.

      Specified by:
      predict in interface IPredictor<T,R>
      Parameters:
      inputs - an Iterator over the input items to be processed
      Returns:
      an Iterator over the predicted output items
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
    • toInputBuffer

      protected abstract FloatBufferMdArray toInputBuffer (List<T> batch)
      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

      protected abstract List<R> fromOutputBuffer (List<T> inputBatch, FloatBufferMdArray outputBatch)
      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