The ONNX version of Chakkhu-OCR-Khmer: reads Khmer and English text lines from pictures with ONNX Runtime only (no PyTorch). It runs on a CPU, in apps, and is ready for phones and the browser (onnxruntime-web). Made by Ing Muyleang.
| File | Size | What |
|---|---|---|
encoder.int8.onnx |
26 MB | line picture → memory + CTC letters (8-bit weights) |
decoder.int8.onnx |
13 MB | writes one Khmer cluster per step (8-bit weights) |
encoder.onnx, decoder.onnx |
51 + 25 MB | the same in fp32 (exactly like PyTorch) |
tokenizer.json |
3,402 tokens: Khmer clusters, Latin, digits, punctuation | |
preprocessor_config.json |
how to prepare a line picture | |
chakkhu_onnx.py, khnormal.py |
the reader (numpy + onnxruntime) and Khmer normalization |
All axes are dynamic: batch, line width (16 – 4,096 px at height 64) and text length.
Tested on all 4,018 KHOB lines (never trained on), on a laptop CPU, reading with beam 4 + CTC check:
| Reader | CER ↓ | same text as PyTorch | ms / line |
|---|---|---|---|
| PyTorch (Chakkhu-OCR-Khmer, full5, reader only) | 3.90% | 100% | 127 |
| ONNX fp32 | 3.90% | 100% | ~190 |
| ONNX int8 | 3.91% | 97.2% | ~190 |
ONNX int8, CTC only (beam=0) |
4.20% | 83% | ~21 |
Raw numbers differ from PyTorch by at most 0.00004. Int8 changes a few lines, but not the overall error rate.
Speeds: measured with the previous version (same size); this run's int8 timings were taken on low-priority cores.
The Khmer word checker (3.58% with PyTorch) is in Chakkhu-OCR-Khmer
(checker/); it needs the PyTorch reader for now.
pip install onnxruntime numpy pillow huggingface_hub
import sys
from huggingface_hub import snapshot_download
folder = snapshot_download("muyleanging/Chakkhu-OCR-Khmer-ONNX"); sys.path.insert(0, folder)
from chakkhu_onnx import Chakkhu
ocr = Chakkhu(folder) # int8; Chakkhu(folder, int8=False) for fp32
print(ocr.read(["line.png"])) # one picture = one text line
print(ocr.read(["line.png"], confidence=True)) # [("…", 0.98)]
print(ocr.read(["line.png"], beam=0)) # fastest: CTC head only
Own code / other languages (preprocessor_config.json): grey picture, height 64 px, width keeps the
shape, values / 255. Pad a batch on the right with 1.0 (white) and pass the real widths.
| Graph | Inputs | Outputs |
|---|---|---|
| encoder | images float (B, 1, 64, W) · widths int64 (B) |
memory (B, 2·W/8, 320) · mem_pad bool · ctc_logp (B, W/8, 3402) · lens int64 |
| decoder | ids int64 (B, L), starts with <s>=1 · memory · mem_pad |
logp (B, L, 3402): log-probs of the next cluster |
Tokens: <pad> 0, <s> 1, </s> 2, <unk> 3, <blank> 4 (CTC). Greedy CTC = best token per column,
repeats merged, blanks removed. Best quality = decoder beam search (4) + CTC draft, every guess scored
0.5 · log P_CTC + 0.5 · log P_decoder (see chakkhu_onnx.py).
Whole pages need a line finder first: the demo has one, and a free API.
Same weights as Chakkhu-OCR-Khmer: CNN + Transformer encoder (6 layers) + CTC head + cluster decoder (3 layers),
18.6M parameters. Results, training data and figures: see the
main model card. Training data:
Chakkhu-OCR-Khmer-Data. Int8: dynamic 8-bit weights for all
matrix products; the small CNN stays fp32. Exported with torch.onnx (opset 18).
@misc{ing2026chakkhu,
author = {Ing, Muyleang},
title = {Chakkhu: A Small Khmer and English Text-Line OCR Model with Line Confidence},
year = {2026},
publisher = {Hugging Face},
howpublished = {\url{https://huggingface.co/muyleanging/Chakkhu-OCR-Khmer}}
}
Apache-2.0. Made by Ing Muyleang. Please credit "Chakkhu by Ing Muyleang".
encoder.onnx 51 MBencoder.int8.onnx 26 MBdecoder.onnx 25 MBdecoder.int8.onnx 13 MB