Skip to content

Using Different Inference Engines

Overview

Since rapidocr>=3.0.0, detection, orientation classification and recognition can use different inference engines. The default backend is ONNX Runtime CPU.

Supported engines include ONNX Runtime, OpenVINO, PaddlePaddle, PyTorch, MNN and TensorRT. Check the model list before selecting a backend because support depends on the model route.

Info

This page covers the common installation and configuration path. Provider-specific options, benchmark data and troubleshooting details are maintained in the complete Chinese reference.

ONNX Runtime

Install the CPU backend:

pip install onnxruntime

ONNX Runtime is the default backend, so no extra parameter is required. GPU execution is not generally recommended for OCR detection because dynamic image shapes can reduce performance.

OpenVINO

pip install openvino
from rapidocr import EngineType, RapidOCR

engine = RapidOCR(
    params={
        "Det.engine_type": EngineType.OPENVINO,
        "Cls.engine_type": EngineType.OPENVINO,
        "Rec.engine_type": EngineType.OPENVINO,
    }
)

PaddlePaddle

Install the PaddlePaddle package appropriate for your operating system and hardware, then select EngineType.PADDLE for the desired stages.

from rapidocr import EngineType, RapidOCR

engine = RapidOCR(params={"Rec.engine_type": EngineType.PADDLE})

PyTorch and Apple MPS

Install PyTorch from the official selector. MPS support requires rapidocr>=3.7.0 and compatible Apple hardware:

from rapidocr import EngineType, RapidOCR

engine = RapidOCR(
    params={
        "Det.engine_type": EngineType.TORCH,
        "Cls.engine_type": EngineType.TORCH,
        "Rec.engine_type": EngineType.TORCH,
        "EngineConfig.torch.use_mps": True,
    }
)

Verify torch.backends.mps.is_available() before running a production workload.

MNN and TensorRT

MNN is supported from rapidocr>=3.6.0. TensorRT is supported from rapidocr>=3.7.0; the engine file is built from the selected ONNX model on first use and requires a compatible NVIDIA environment.

For installation details, provider-specific options and troubleshooting, see the Chinese inference-engine reference.

Comments