Skip to main content

openocr-mlt

Multilingual OCR with ScriptMoE ONNX Prefill/Decode recognition and PP-OCRv6 medium text detection. Run whole-page OCR, detection, or cropped text recognition locally.

Installation

Tested on Linux x86_64 with Python 3.10. Create a virtual environment and install the package.

python3.10 -m venv .venv-ocr
source .venv-ocr/bin/activate
python -m pip install openocr-mlt

On Linux x86_64 this installation includes the CPU and CUDA providers in one ONNX Runtime package. NVIDIA CUDA requires a compatible driver. On the first CUDA inference, the Python task API reuses compatible system libraries or prepares the pinned CUDA 12 and cuDNN 9 libraries in the user's cache. CPU inference does not need these libraries. The first GPU setup can download about 1.32 GB of runtime libraries, separate from the model bundle. Download progress and source retries are written to standard error. If preparation fails, correct the reported issue and create a new OCR instance to retry, or set device="cpu". PyTorch is optional.

For an existing 0.4.0 CPU or CUDA installation, use a new environment for this version and reuse the model cache. Only one ONNX Runtime distribution and one OCR package may be installed in each environment.

Python API

from openocr_mlt import OpenOCRMLT

with OpenOCRMLT(task="ocr") as ocr:
    page = ocr(image_path="page.jpg")
    print(page.text)

with OpenOCRMLT(task="det", device="cpu") as detector:
    boxes = detector(image_path="page.jpg")
    print([box.points for box in boxes])

with OpenOCRMLT(task="rec", device="cpu") as recognizer:
    lines = recognizer(image_path="crop.jpg")
    print([(line.text, line.score) for line in lines])

Pass an existing image path or use the image argument with a PIL image or a uint8 NumPy array. Arrays use BGR by default. Pass color_order="RGB" for RGB arrays. The default device is "auto". The runtime uses CUDA when it can initialize the selected models and uses CPU when CUDA is unavailable. Use device="cpu" or device="cuda:0" to request a specific device. Explicit model directories and the original methods remain supported.

Model preparation

The first task call downloads the FP32 model bundle if it is absent from the cache. The bundle is hosted on ModelScope. Hugging Face and its mirror are fallback sources. The downloader verifies the archive and all 40 model files before installing the cache. The default cache is $XDG_CACHE_HOME/openocr-mlt or ~/.cache/openocr-mlt. The next task can reuse it offline.

Import a local archive in an offline environment with the following command.

python -m openocr_mlt fetch-models \
  --source ./scriptmoe-medium-fp32-20261101-v1.tar.gz --offline

Set offline=True on the Python task to use local models and CUDA libraries only. The fetch-models command prints the verified recognition and detector directories.

Command line

python -m openocr_mlt fetch-models --cache-dir ./models
python -m openocr_mlt ocr ./page.jpg \
  --model-dir ./models/scriptmoe-medium-fp32-20261101-v1/recognition \
  --det-model-dir ./models/scriptmoe-medium-fp32-20261101-v1/ppocrv6-medium-det-bce-v1 \
  --device cpu

The CLI also supports detect and recognize. For CLI CUDA use, prepare the CUDA cache with a Python task first or provide compatible local libraries. Run python -m openocr_mlt --help for the available options.

Model Evaluation

The FP32 graphs were evaluated with openocr-mlt 0.3.0.dev14. The model bundle is unchanged.

Task Data Result
CUDA recognition TextMuSS, 10,899 crops Official normalized weighted accuracy 85.0812%; ten-group macro accuracy 81.0928%
Whole-page OCR, CPU and CUDA Fixed CC-OCR subset, 200 pages across ten languages, development/held-out split 100/100 Held-out text F1: macro 72.5849%, micro 79.4545%

Those model evaluations used Linux x86_64, Python 3.10.12, ONNX Runtime 1.20.0, an Intel Xeon Gold 6226R CPU, and an NVIDIA RTX 3090 GPU. One CPU/CUDA recognition whitespace difference was observed on TextMuSS. Additional platforms, hardware and quantized execution remain future work.

Sources

  • ScriptMoE: multilingual recognition model and decoding design.
  • ppocrv6_onnx: detection preprocessing and postprocessing reference.
  • PP-OCRv6 medium: detector distributed through Paddle's official model storage.

Component attribution and licensing information are included in the package's THIRD_PARTY_NOTICES.txt and in the model repository's THIRD_PARTY_NOTICES.md.

Metadata

Release files for openocr-mlt 0.5.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for openocr-mlt 0.5.1
File Size Uploaded Provenance Actions
openocr_mlt-0.5.1.tar.gz 114.7 kB Without provenance Details for openocr_mlt-0.5.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for openocr-mlt 0.5.1
File Interpreter ABI Platform Actions
openocr_mlt-0.5.1-py3-none-any.whl Python 3 none any Details for openocr_mlt-0.5.1-py3-none-any.whl

Total release size: 215.1 kB

Release files / openocr_mlt-0.5.1.tar.gz

Download URL openocr_mlt-0.5.1.tar.gz
Size 114.7 kB
Tags Source
SHA-256 checksum
How to use checksums
8f679bf428a2723be83bb9675619b5a9d9e53729c950398cea421192f627238d
BLAKE2b-256 checksum
How to use checksums
85dabae74f5f6797350a18f0f269bd649fbef4abefcb4f97f6f15a9c789c3864
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.9

Release files / openocr_mlt-0.5.1-py3-none-any.whl

Download URL openocr_mlt-0.5.1-py3-none-any.whl
Size 100.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4a1baf269ac32fe446b108a0dc319d14257f45d2a3c4f7df5d2fb44f795b1703
BLAKE2b-256 checksum
How to use checksums
85c3e1444d9fbdf643dd16ebbabefc9fad40e9d0509aaabbfbf654f9516369f2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.9

Security for openocr-mlt 0.5.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page