AksonOCR

AksonOCR-Lite

β–Ά Try the live demo

Code, docs and issues: github.com/Remtir/AksonOCR-Lite

Fast, open-source Thai document OCR with a grapheme-cluster CTC recognizer. Turns PDFs and images into Markdown, plain text or JSON with layout blocks, reading order, text-line boxes and tables. Runs on ONNX Runtime, on CPU or GPU, with no PyTorch or Paddle install.

Try it in your browser β†’ Upload a page image or PDF (up to 7 MB) and see the Markdown, layout and tables. No install.

81M params, runs on CPU: ~3Γ— faster per page than 2B-param OCR VLMs on a GPU, and more accurate than VLMs on average across MDPBench, ThaiOCRBench and SEA-DocBench (benchmarks).

pip install git+https://github.com/Remtir/AksonOCR-Lite
aksonocr invoice.pdf > invoice.md

The PyPI package (pip install aksonocr-lite) is coming soon; until then, install from GitHub as above.

  • Thai first: the text recognizer is trained for Thai (with English), predicting whole grapheme clusters so stacked vowels and tone marks come out in the right order.
  • Document structure: 25 layout classes (titles, paragraphs, tables, figures, headers/footers, ...) and reading order from PP-DocLayoutV3; tables become HTML with row/column spans.
  • Photos too: page-orientation correction, upside-down line detection, and optional page dewarping.
  • Light: about 330 MB of weights by default (β‰ˆ620 MB with dewarping), fetched from the Hugging Face Hub on first run.
Layout blocks and text lines on a Thai government letterLayout blocks and text lines on a handwritten page photoLayout blocks and text lines on a financial statement

Layout blocks in reading order, table cells (TATR grid), then detected text lines. Made with tools/visualize_gif.py.

Benchmarks

MDPBench-th 85.6 with --dewarp (79.5 default) Β· ThaiOCRBench DP 0.640 Β· SEA-DocBench-th text NED 0.058 Β· 1.5 s per page on CPU only.

Accuracy of AksonOCR-Lite vs 12 other Thai OCR systems: average of MDPBench-th, ThaiOCRBench Document parsing and SEA-DocBench-th

Speed of AksonOCR-Lite vs three VLMs, average over three benchmarks: seconds per page one at a time, pages per second batched

Averages over MDPBench-th, ThaiOCRBench Document parsing and SEA-DocBench-th. Full benchmark β†’ per-benchmark charts, default vs --dewarp, speed tables, text recognition only.

Requirements

Python 3.10 or newer (CI tests 3.10 and 3.13)
OS Linux, macOS (Apple Silicon). Windows is untested so far.
Hardware Any x86-64 or ARM64 CPU. No GPU needed; NVIDIA GPU optional (see GPU).
RAM about 1.3 GB peak for one page, about 2.8 GB with --dewarp
Disk about 330 MB of model weights, plus 290 MB for --dewarp, in the Hugging Face cache (~/.cache/huggingface)
Network only on first run, to download the weights. Use AKSONOCR_WEIGHTS for fully offline machines.

No PyTorch, Paddle or system packages are needed. pip installs everything else: onnxruntime, numpy, opencv-python-headless, pillow, pypdfium2 (PDF rendering), pyclipper, shapely and huggingface_hub.

For the GPU build (onnxruntime-gpu): an NVIDIA driver with CUDA 12 and cuDNN 9, the versions current onnxruntime-gpu wheels are built against.

Usage

Command line

aksonocr page.jpg                        # Markdown to stdout
aksonocr report.pdf --out out/           # out/report.md (every page of the PDF)
aksonocr scan.png -f json -o out/        # boxes, blocks, lines, confidences
aksonocr photo.jpg --dewarp              # flatten a photographed / curled page
aksonocr doc.pdf --device cpu --dpi 200 --max-pages 10

Python

import aksonocr_lite

conv = aksonocr_lite.load()                 # device="auto" | "cpu" | "cuda", dewarp=False, tables=True, ...
for page in conv.convert("report.pdf"):     # path, bytes, PIL.Image or BGR numpy array
    print(page.markdown)
    for block in page.blocks:               # reading order
        print(block.label, block.bbox, block.text or block.html)
    for line in page.lines:
        print(line.text, line.confidence, line.poly)

lines = conv.ocr(bgr_image)                  # text lines only, no layout

Page fields: markdown, text, blocks (label, bbox, score, order, text, html, line_ids), lines (text, confidence, bbox, poly), rotation, dewarped, width, height, timings. All coordinates are in the pixel space of the (rotated, dewarped) page image.

GPU

The default install runs on CPU, on Linux and macOS (Apple Silicon). For CUDA, swap ONNX Runtime for its GPU build:

pip uninstall -y onnxruntime && pip install onnxruntime-gpu

device="auto" then picks CUDA. Inputs have variable shapes, so the CPU path is often just as fast for single pages; the GPU pays off mostly with dewarping and large batches.

Offline / custom weights

Set AKSONOCR_WEIGHTS=/path/to/dir to load models from a local folder instead of the Hub. It must contain layout.onnx det.onnx doc_ori.onnx textline_ori.onnx rec.onnx rec_charset.json tatr.onnx, plus dewarp_mask.onnx dewarp_grid.onnx for --dewarp.

How it works

page image ─┬─ (dewarp: MonkeyOCRv2 preprocessor)            optional
            β”œβ”€ page orientation: PP-LCNet doc_ori             0/90/180/270
            β”œβ”€ layout + reading order: PP-DocLayoutV3        ┐
            β”œβ”€ text lines: PP-OCRv6_medium_det (DB)           β”‚ run on the same page
            β”‚    └─ line orientation (PP-LCNet textline_ori)  β”‚
            β”‚    └─ recognition: AksonOCR Thai CTC (+180Β° re-read, keeps the more confident reading)
            β”œβ”€ tables: re-detect text in the crop β†’ TATR v1.1 grid β†’ fill cells with OCR lines β†’ HTML
            └─ merge: each line β†’ the layout block holding its centre (nearest block as fallback),
                      blocks in reading order β†’ Markdown

Thai recognizer: grapheme-cluster CTC

Thai stacks vowels and tone marks on the consonant, so one glyph can be 2–3 code points (ΰΈœΰΈΉΰΉ‰ = ผ + ΰΈΉ + ΰΉ‰). Instead of emitting them one by one, the recognizer predicts the whole cluster as one token.

Step by step: the recognizer's real CTC output on a Thai line, spelled as character tokens (22 symbols, stacked marks as 2–3 symbols in one spot) and as cluster tokens (15 symbols, one per glyph column)

Real CTC output of the recognizer on a photographed line; made with tools/cluster_gif.py.

  • Correct order, always: marks inside a cluster always come out in Unicode order, never swapped.
  • No impossible output: only real clusters are in the vocabulary (2,149 of 2,455 classes).
  • Shorter sequence: one token per glyph (15 vs 22 on the line above).
  • Tiny and fast: 1.5M parameters, 88.6% exact match at 8 ms per line on one CPU thread (comparison).

Details worth knowing:

  • Text in tables is read by the Thai recognizer, not by the table model: TATR only provides the grid.
  • The detector often boxes a lone Thai vowel or tone mark; such fragments are dropped before recognition.
  • Lines are batched only with lines of nearly the same width. Padding changes the recognizer's attention and cost about 3 points of exact-match accuracy when widths were mixed freely.

Limitations

  • Photographed pages are harder than digital ones. On MDPBench-th the default pipeline scores 89.5 on digital pages but 76.2 on photos (curl, shadow, glare, perspective). --dewarp brings photos to 84.3 at about twice the weights and extra time per page; very dark, folded or blurred photos still lose text.
  • Handwriting is weak. The recognizer was trained for printed Thai and English; handwritten notes and filled-in forms come out with many errors.
  • No formula or picture understanding. Math is read as plain text lines (no LaTeX). Figures and charts become <figure> blocks holding only the text printed in them, with no description of the picture.
  • Dense multi-column layouts such as newspapers often get the reading order or column split wrong.
  • Thai and English only. Other scripts and vertical text are not supported.

Models and licenses

Stage Model License
Layout + reading order PP-DocLayoutV3 Apache-2.0
Text detection PP-OCRv6_medium_det Apache-2.0
Page / line orientation PP-LCNet_x1_0_doc_ori, textline_ori Apache-2.0
Text recognition AksonOCR Thai recognizer (fine-tuned PP-OCRv6_tiny_rec), model card Apache-2.0
Table structure Table Transformer v1.1-all (Microsoft) MIT
Dewarping (optional) MonkeyOCRv2 document preprocessor Apache-2.0

All weights download from one Hugging Face repo, Remtir/AksonOCR-Lite; the PaddlePaddle models there are unmodified copies of the official ONNX exports linked above. The code is Apache-2.0 (LICENSE); third-party attributions are in NOTICE. Every model is permissively licensed, so AksonOCR-Lite can be used commercially. PDFs are rendered with pypdfium2 (Apache-2.0/BSD), not PyMuPDF (AGPL).

Files in this repository

File What it is Origin License
rec.onnx, rec_charset.json Thai + English text-line recognizer (ours, model card) fine-tuned from PaddlePaddle PP-OCRv6_tiny_rec Apache-2.0
layout.onnx layout blocks + reading order PaddlePaddle/PP-DocLayoutV3_onnx, unmodified copy Apache-2.0
det.onnx text-line detection PaddlePaddle/PP-OCRv6_medium_det_onnx, unmodified copy Apache-2.0
doc_ori.onnx, textline_ori.onnx page / text-line orientation PP-LCNet_x1_0_doc_ori_onnx, PP-LCNet_x1_0_textline_ori_onnx, unmodified copies Apache-2.0
tatr.onnx table structure (rows, columns, headers, spans) microsoft/table-transformer-structure-recognition-v1.1-all, converted MIT
dewarp_mask.onnx, dewarp_grid.onnx page segmentation + dewarping grid (optional) MonkeyOCRv2 document preprocessor, converted Apache-2.0
config.json pipeline manifest (components, source revisions) ours Apache-2.0

The aksonocr-lite package downloads these on first use. The four PaddlePaddle files are byte-identical copies of the official inference.onnx exports, kept here so the whole pipeline loads from one repository.

Development

pip install -e .[dev]
pytest -m "not e2e"          # unit tests, no weights needed
pytest                       # + end-to-end test (downloads weights)

tools/ holds the scripts that produced the ONNX files (they need Paddle/PyTorch and are not part of the package): export_tatr.py, export_dewarp.py.

Acknowledgements

AksonOCR-Lite stands on open work from many teams:

Citation

@software{aksonocr_lite,
  author = {Jaknamon, Teetouch},
  title  = {AksonOCR-Lite: Thai Document OCR with Grapheme-Cluster CTC Recognition},
  version = {1.0.0},
  year   = {2026},
  url    = {https://github.com/Remtir/AksonOCR-Lite}
}
Downloads last month
272
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support

Space using Remtir/AksonOCR-Lite 1