Class OnnxDetectionPredictor
- All Implemented Interfaces:
-
IDetectionPredictor,IPredictor<BufferedImage,,List > AutoCloseable
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a text detection predictor with the specified properties. -
Method Summary
Modifier and TypeMethodDescriptionstatic OnnxDetectionPredictorCreates a new text detection predictor using an existing pre-trained DBNet model, stored on disk.static OnnxDetectionPredictordbNet(String modelPath, IOrtSessionOptionsCreator ortSessionOptionsCreator) Creates a new text detection predictor using an existing pre-trained DBNet model, stored on disk.static OnnxDetectionPredictorCreates a new text detection predictor using an existing pre-trained EasyOCR CRAFT model, stored on disk.static OnnxDetectionPredictoreasyOcr(String modelPath, IOrtSessionOptionsCreator ortSessionOptionsCreator) Creates a new text detection predictor using an existing pre-trained EasyOCR CRAFT model, stored on disk.static OnnxDetectionPredictorCreates a new text detection predictor using an existing pre-trained FAST model, stored on disk.static OnnxDetectionPredictorfast(String modelPath, IOrtSessionOptionsCreator ortSessionOptionsCreator) Creates a new text detection predictor using an existing pre-trained FAST model, stored on disk.fromOutputBuffer(List<BufferedImage> inputBatch, FloatBufferMdArray outputBatch) Converts ONNX runtime model batched output MD-array buffer to a list of predictor outputs.Returns the text detection predictor properties.static OnnxDetectionPredictorCreates a new text detection predictor using an existing pre-trained LinkNet model, stored on disk.static OnnxDetectionPredictorlinkNet(String modelPath, IOrtSessionOptionsCreator ortSessionOptionsCreator) Creates a new text detection predictor using an existing pre-trained LinkNet model, stored on disk.static OnnxDetectionPredictorCreates a new text detection predictor using an existing pre-trained PaddleOCR model, stored on disk.static OnnxDetectionPredictorpaddleOcr(String modelDirPath, IOrtSessionOptionsCreator ortSessionOptionsCreator) Creates a new text detection predictor using an existing pre-trained PaddleOCR model, stored on disk.static OnnxDetectionPredictorCreates a new text detection predictor using an existing pre-trained PaddleOCR model, stored on disk.static OnnxDetectionPredictorpaddleOcr(String modelPath, String configPath, IOrtSessionOptionsCreator ortSessionOptionsCreator) Creates a new text detection predictor using an existing pre-trained PaddleOCR model, stored on disk.protected FloatBufferMdArraytoInputBuffer(List<BufferedImage> batch) Converts predictor inputs to an ONNX runtime model batched input MD-array buffer.Methods inherited from class com.itextpdf.pdfocr.onnx.AbstractOnnxPredictor
close, predictMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.lang.AutoCloseable
closeMethods inherited from interface com.itextpdf.pdfocr.onnx.IPredictor
predict, predict
-
Constructor Details
-
OnnxDetectionPredictor
Creates a text detection predictor with the specified properties.- Parameters:
-
properties- properties of the predictor
-
-
Method Details
-
dbNet
Creates a new text detection predictor using an existing pre-trained DBNet model, stored on disk.This can be used to load the following models from OnnxTR:
- db_resnet50
- db_resnet50 (8-bit quantized)
- db_resnet34
- db_resnet34 (8-bit quantized)
- db_mobilenet_v3_large
- db_mobilenet_v3_large (8-bit quantized)
These models output boxes of words.
- Parameters:
-
modelPath- path to the pre-trained model - Returns:
- a new predictor with the DBNet model loaded
-
dbNet
public static OnnxDetectionPredictor dbNet(String modelPath, IOrtSessionOptionsCreator ortSessionOptionsCreator) Creates a new text detection predictor using an existing pre-trained DBNet model, stored on disk.This can be used to load the following models from OnnxTR:
- db_resnet50
- db_resnet50 (8-bit quantized)
- db_resnet34
- db_resnet34 (8-bit quantized)
- db_mobilenet_v3_large
- db_mobilenet_v3_large (8-bit quantized)
These models output boxes of words.
- Parameters:
-
modelPath- path to the pre-trained model -
ortSessionOptionsCreator- the ONNX runtime session options creator - Returns:
- a new predictor with the DBNet model loaded
-
fast
Creates a new text detection predictor using an existing pre-trained FAST model, stored on disk. This is the default text detection model in OnnxTR.This can be used to load the following models from OnnxTR:
These models output boxes of words.
- Parameters:
-
modelPath- path to the pre-trained model - Returns:
- a new predictor with the FAST model loaded
-
fast
public static OnnxDetectionPredictor fast(String modelPath, IOrtSessionOptionsCreator ortSessionOptionsCreator) Creates a new text detection predictor using an existing pre-trained FAST model, stored on disk. This is the default text detection model in OnnxTR.This can be used to load the following models from OnnxTR:
These models output boxes of words.
- Parameters:
-
modelPath- path to the pre-trained model -
ortSessionOptionsCreator- the ONNX runtime session options creator - Returns:
- a new predictor with the FAST model loaded
-
linkNet
Creates a new text detection predictor using an existing pre-trained LinkNet model, stored on disk.This can be used to load the following models from OnnxTR:
- linknet_resnet50
- linknet_resnet50 (8-bit quantized)
- linknet_resnet34
- linknet_resnet34 (8-bit quantized)
- linknet_resnet18
- linknet_resnet18 (8-bit quantized)
These models output boxes of words.
- Parameters:
-
modelPath- path to the pre-trained model - Returns:
- a new predictor with the LinkNet model loaded
-
linkNet
public static OnnxDetectionPredictor linkNet(String modelPath, IOrtSessionOptionsCreator ortSessionOptionsCreator) Creates a new text detection predictor using an existing pre-trained LinkNet model, stored on disk.This can be used to load the following models from OnnxTR:
- linknet_resnet50
- linknet_resnet50 (8-bit quantized)
- linknet_resnet34
- linknet_resnet34 (8-bit quantized)
- linknet_resnet18
- linknet_resnet18 (8-bit quantized)
These models output boxes of words.
- Parameters:
-
modelPath- path to the pre-trained model -
ortSessionOptionsCreator- the ONNX runtime session options creator - Returns:
- a new predictor with the LinkNet model loaded
-
paddleOcr
Creates a new text detection predictor using an existing pre-trained PaddleOCR model, stored on disk.Only models in the ONNX format are supported. Since, by default, PaddleOCR does not provide models in the ONNX format, you might need to do a model conversion yourself. Check out this page for information on how to do that.
This method expects the directory to contain two files:
inference.onnx- the inference model in the ONNX formatinference.yml- the configuration file for the model in YAML
This method can be used to load the following PaddleOCR models:
These models output boxes of text lines. Make sure you choose a recognition model that can handle spaces.
- Parameters:
-
modelDirPath- path to the directory with the model and its configuration file - Returns:
- a new predictor with the PaddleOCR model loaded
- Throws:
-
IOException- if any I/O error occurs while loading configuration file
-
paddleOcr
public static OnnxDetectionPredictor paddleOcr(String modelDirPath, IOrtSessionOptionsCreator ortSessionOptionsCreator) throws IOException Creates a new text detection predictor using an existing pre-trained PaddleOCR model, stored on disk.Only models in the ONNX format are supported. Since, by default, PaddleOCR does not provide models in the ONNX format, you might need to do a model conversion yourself. Check out this page for information on how to do that.
This method expects the directory to contain two files:
inference.onnx- the inference model in the ONNX formatinference.yml- the configuration file for the model in YAML
This method can be used to load the following PaddleOCR models:
These models output boxes of text lines. Make sure you choose a recognition model that can handle spaces.
- Parameters:
-
modelDirPath- path to the directory with the model and its configuration file -
ortSessionOptionsCreator- the ONNX runtime session options creator - Returns:
- a new predictor with the PaddleOCR model loaded
- Throws:
-
IOException- if any I/O error occurs while loading configuration file
-
paddleOcr
public static OnnxDetectionPredictor paddleOcr(String modelPath, String configPath) throws IOException Creates a new text detection predictor using an existing pre-trained PaddleOCR model, stored on disk.Only models in the ONNX format are supported. Since, by default, PaddleOCR does not provide models in the ONNX format, you might need to do a model conversion yourself. Check out this page for information on how to do that.
This method can be used to load the following PaddleOCR models:
These models output boxes of text lines. Make sure you choose a recognition model that can handle spaces.
- Parameters:
-
modelPath- path to the pre-trained model in the ONNX format -
configPath- path to the configuration file for the model - Returns:
- a new predictor with the PaddleOCR model loaded
- Throws:
-
IOException- if any I/O error occurs while loading configuration file
-
paddleOcr
public static OnnxDetectionPredictor paddleOcr(String modelPath, String configPath, IOrtSessionOptionsCreator ortSessionOptionsCreator) throws IOException Creates a new text detection predictor using an existing pre-trained PaddleOCR model, stored on disk.Only models in the ONNX format are supported. Since, by default, PaddleOCR does not provide models in the ONNX format, you might need to do a model conversion yourself. Check out this page for information on how to do that.
This method can be used to load the following PaddleOCR models:
These models output boxes of text lines. Make sure you choose a recognition model that can handle spaces.
- Parameters:
-
modelPath- path to the pre-trained model in the ONNX format -
configPath- path to the configuration file for the model -
ortSessionOptionsCreator- the ONNX runtime session options creator - Returns:
- a new predictor with the PaddleOCR model loaded
- Throws:
-
IOException- if any I/O error occurs while loading configuration file
-
easyOcr
Creates a new text detection predictor using an existing pre-trained EasyOCR CRAFT model, stored on disk.Only models in the ONNX format are supported. Since, by default, EasyOCR does not provide models in the ONNX format, you might need to do a model conversion yourself.
This can be used to load the following models from EasyOCR:
These models output boxes of text lines. Make sure you choose a recognition model that can handle spaces.
- Parameters:
-
modelPath- path to the pre-trained model - Returns:
- a new predictor with the EasyOCR CRAFT model loaded
-
easyOcr
public static OnnxDetectionPredictor easyOcr(String modelPath, IOrtSessionOptionsCreator ortSessionOptionsCreator) Creates a new text detection predictor using an existing pre-trained EasyOCR CRAFT model, stored on disk.Only models in the ONNX format are supported. Since, by default, EasyOCR does not provide models in the ONNX format, you might need to do a model conversion yourself.
This can be used to load the following models from EasyOCR:
These models output boxes of text lines. Make sure you choose a recognition model that can handle spaces.
- Parameters:
-
modelPath- path to the pre-trained model -
ortSessionOptionsCreator- the ONNX runtime session options creator - Returns:
- a new predictor with the EasyOCR CRAFT model loaded
-
getProperties
Returns the text detection predictor properties.- Returns:
- the text detection predictor properties
-
toInputBuffer
Converts predictor inputs to an ONNX runtime model batched input MD-array buffer.- Specified by:
-
toInputBufferin classAbstractOnnxPredictor<BufferedImage,List > - Parameters:
-
batch- batch of raw predictor inputs - Returns:
- batched model input MD-array buffer
-
fromOutputBuffer
protected List<List> fromOutputBuffer(List<BufferedImage> inputBatch, FloatBufferMdArray outputBatch) Converts ONNX runtime model batched output MD-array buffer to a list of predictor outputs.- Specified by:
-
fromOutputBufferin classAbstractOnnxPredictor<BufferedImage,List > - Parameters:
-
inputBatch- list of raw predictor inputs, matching the output -
outputBatch- batched model output MD-array buffer - Returns:
- a list of predictor output
-