OnnxTR

raw JSON →
0.8.1 verified Fri May 01 auth: no python

Onnx Text Recognition (OnnxTR) is an Onnx-wrapped version of docTR that provides high-performance OCR on documents. It supports text detection, recognition, and end-to-end OCR pipelines using pre-trained models exported to ONNX. Current version 0.8.1 requires Python >=3.10 and <4. Release cadence is irregular.

pip install onnxtr
error ModuleNotFoundError: No module named 'doctr'
cause onnxtr depends on docTR at runtime, which is not automatically installed.
fix
Install docTR: pip install python-doctr
error AttributeError: 'NoneType' object has no attribute 'shape'
cause Image path not found or image not loaded correctly.
fix
Check file path; use absolute path or verify file exists.
error RuntimeError: Input type (unsigned char) and bias type (float) should be the same
cause Image not in expected dtype (uint8 vs float). Usually when converting from PIL or NumPy array incorrectly.
fix
Ensure image is uint8 and values in [0,255]. If using tensor, use .to(torch.uint8) or convert properly.
breaking onnxtr 0.8.0+ requires Python >=3.10; Python 3.9 is not supported.
fix Upgrade Python to 3.10 or later; or use onnxtr<0.8.0 (not recommended).
gotcha Input images must be RGB, not BGR (openCV default). onnxtr reads images as RGB by default via docTR's DocumentFile, but using openCV directly and then converting may cause color issues.
fix Use DocumentFile.from_images() or ensure image is converted to RGB: cv2.cvtColor(img, cv2.COLOR_BGR2RGB).
deprecated The standalone OnnxTR model export tools are deprecated; use docTR's native ONNX export instead.
fix Use docTR's onnx_export utilities. See docTR documentation.

Basic usage of onnxtr to perform OCR on an image and print the recognized text.

from onnxtr import OCRPredictor
from doctr.io import DocumentFile

# Initialize predictor with detection + recognition models
predictor = OCRPredictor(
    det_arch='db_resnet50',
    reco_arch='crnn_vgg16_bn',
    pretrained=True
)

# Load a document image
doc = DocumentFile.from_images("path/to/image.jpg")

# Perform OCR
result = predictor(doc)
print(result.render())