Thai + English OCR that doesn't need a GPU. A ~0.6M-parameter CTC line recogniser, nudged toward handwriting, with the receipts to prove (and bound) it.
$ whoami
KAO-OCR General is an ONNX, CPU-first OCR engine for Thai and English. It finds text lines, crops them, reads each crop with a tiny CTC recogniser, and stitches the result back together in reading order. No GPU, no serving stack, no gigabyte checkpoints: pip install five small packages and go.
Release 1.0a changes exactly one thing: the line recogniser has been gently fine-tuned on Thai handwriting. Everything else in the pipeline is left exactly as it was.
| Runtime | ONNX Runtime, CPUExecutionProvider |
| Recogniser | CTC, ~0.6M parameters, 530 output classes (blank + 528 glyphs + space) |
| Input | 3 × 48 × W tensor (BGR, scaled to [-1, 1]), dynamic width |
| Decoding | greedy CTC |
| Changed in 1.0a | rec.onnx, pytorch/rec_weights.pt |
| Untouched | detector (det.onnx), second recogniser (rec2.onnx), runtime/, LICENSE, NOTICE |
page ──► det.onnx ──► line crops ──► rec.onnx (CTC) ──► reading order ──► text
▲
the only weights touched in 1.0a
The runtime also handles orientation, deskew and reading order, so you can feed it ordinary scans and photos.
$ pip install and run
pip install -r requirements.txt
python inference.py page.png # text to stdout
python inference.py scans/ -o out/ # a whole folder -> out/<name>.txt
python inference.py page.png --json # full result (lines, boxes, ...) as JSON
Or from Python:
from runtime.line_engine import LineOCR # run from inside this repo folder
ocr = LineOCR(".", threads=1)
result = ocr.read("page.png") # path, bytes, numpy array or PIL image
print(result["text"]) # full text in reading order
For batch jobs, N processes with 1 thread each is usually the better trade than 1 process with N threads.
Numbers
ThaiOCRBench, OCR tasks
Metric: NLS = 1 − normalised edit distance, 0–100, higher is better. 30 pages sampled per task type.
| Task type | NLS |
|---|---|
| Full-page OCR | 70.8 |
| Text recognition | 53.1 |
| Handwritten content extraction | 18.4 |
| Fine-grained text recognition | 15.4 |
| Mean over the four OCR tasks | 39.4 |
Read this table with the right amount of salt:
- The scorers are mine, not the benchmark authors' official scripts, and the pages are a sample (
n = 30per task). Don't line these numbers up against anyone's leaderboard. - Parsing tasks (tables, charts, document parsing) are
n/aon purpose: General is an OCR-only engine and writes no Markdown. - There is no baseline column. The baseline run did not complete cleanly in my harness, so I make no before/after claim on this benchmark. The A/B I can stand behind is the held-out validation below.
- Handwriting is the hard mode, and the table says so.
Held-out validation (recogniser only, greedy CTC)
Sentence-disjoint split: no sentence in validation appears in training.
| CER, lower is better | before | after (shipped) | relative |
|---|---|---|---|
| Handwriting lines | 0.9200 | 0.8036 | −12.7% |
| Printed lines (rendered, synthetic) | 0.0436 | 0.0290 | −33.5% |
"Before" is the recogniser this work started from. The honest read: a 12.7% relative CER reduction on handwriting is real movement, but a CER of 0.80 means handwriting is far from solved for a 0.6M-parameter model. The printed number is measured on lines rendered with the same family of Thai fonts as the training replay, so treat it as "printed text did not regress", not as a real-world printed-text claim.
How it was made
A small, careful fine-tune. The goal was to teach handwriting without making printed text worse.
- Data. Two public Thai handwriting corpora of line crops, pooled. Split by an MD5 hash of the normalised sentence, so a sentence written by several people (or present in both corpora) can never land in train and validation at once. 2% validation, 3% test, the rest train.
- Light touch. CTC fine-tuning of the recogniser only.
- Replay. About 25% of every training batch is printed text: the training sentences re-rendered with Thai fonts (random font, size, ink, background, blur), so the model keeps seeing the kind of text it already read well.
- Weight-space blend (WiSE-FT).
w = (1 − α)·w_original + α·w_finetuned. α is not guessed: I sweepα ∈ {0.3, 0.5, 0.7, 1.0}on validation and take the best handwriting CER among the α values whose printed CER stays within1.05 × baseline + 0.005. The pure fine-tune qualified, so α = 1.00 shipped. - Verified export. Two gates. Before training, a PyTorch re-implementation must reproduce the shipped
rec.onnxto within5e-3max abs difference, or training refuses to start. After training, the exported ONNX is checked against PyTorch on dynamic batch and width shapes: max |torch − onnx| = 1.2e-05.
| Hyper-parameter | Value |
|---|---|
| Optimiser | AdamW, β = (0.9, 0.98), weight decay 0.01 |
| LR schedule | 1e-4 peak, 100 warm-up steps, cosine to a 2% floor |
| Batch / clip | 64 / grad-norm 5.0 |
| Epochs | ≤ 5, early stopping with patience 3 |
| Checkpoint pick | lowest handwriting CER + 0.5 × printed CER on validation |
| Max line width | 1600 px (height fixed at 48) |
| Augmentation | brightness, contrast, blur, ±15% horizontal stretch, ±2° rotation, padding |
| Precision | bf16 autocast on GPU |
| Seed | 42 |
Limitations
- Only the line recogniser was fine-tuned. If the detector misses a handwritten line, the recogniser never gets to see it.
- Handwriting remains much harder than print for a model this small. Expect real gains, not magic.
- Fine-tuned on single lines, not on page layouts; layout behaviour is whatever the untouched parts of the pipeline do.
- OCR only: no tables, no Markdown.
- Benchmark numbers come from my own sampled run and scorers.
- It is an alpha. Test on your own data before you trust it.
Disclaimer & Credit
A side-project, honestly. I made this for fun. I'm not an OCR guy; I just wanted to add one more option to the Thai OCR toolbox. It's for my own use, I'm not trying to compete with anyone, and it comes with the usual alpha-software caveats: no warranty, check it on your own data.
Credit where it's due. KAO-OCR General is a fine-tune of iapp/OpenThai2.1-OCR-Text-20261118 (tag v2.1.4). I changed rec.onnx and pytorch/rec_weights.pt; everything else, including the LICENSE and NOTICE files, is theirs and is kept as shipped. Their original model card, which also documents the full runtime API (lines, boxes, confidence), is preserved as OPENTHAI_ORIGINAL_README.md.
Thank you 💛
- iApp Technology, for building and openly releasing a genuinely good Thai OCR to start from.
- The Typhoon team, for the great Thai OCR work and for ThaiOCRBench, which I used for evaluation.
Thanks for making good Thai models in the open. Without you two, this repo would just be an empty folder; any mistakes are mine.
License
Apache-2.0, same as the model it was fine-tuned from; see LICENSE and NOTICE (upstream notices, including third-party OCR components, are preserved there). The training data comes from two public Thai handwriting corpora, iapp/thai_handwriting_dataset and sivakorn-su/thai-handwriting-textdisjoint-v1, which carry their own terms: check them before commercial use.