Using Local Models
Local models can be configured through a YAML file or the params mapping. Detection, orientation classification and recognition use their corresponding model_path or model_dir fields.
PaddlePaddle model directories¶
PaddlePaddle models use model_dir. Recognition models may also require rec_keys_path:
from rapidocr import EngineType, OCRVersion, RapidOCR
engine = RapidOCR(
params={
"Rec.model_dir": "models/paddle/PP-OCRv6_rec_tiny",
"Rec.rec_keys_path": "models/paddle/PP-OCRv6_rec_tiny/ppocrv6_tiny_dict.txt",
"Rec.engine_type": EngineType.PADDLE,
"Rec.ocr_version": OCRVersion.PPOCRV6,
}
)
result = engine("test.jpg")
print(result)
Other model formats¶
ONNX, PyTorch and other file-based backends use model_path:
from rapidocr import EngineType, OCRVersion, RapidOCR
engine = RapidOCR(
params={
"Det.model_path": "models/torch/PP-OCRv6_det_tiny.pth",
"Det.engine_type": EngineType.TORCH,
"Det.ocr_version": OCRVersion.PPOCRV6,
}
)
result = engine("test.jpg")
print(result)
The model architecture, OCR version, dictionary and preprocessing parameters must match. See the model list and parameter reference before combining custom files.