ThaOCR textdet β text-line detector for Khmer + English documents (DB, ONNX)
Stage 2 of 5 of the ThaOCR pipeline. Finds text lines inside a page or region. DB (Differentiable Binarization) with the
PaddleOCR PP-OCRv5 mobile backbone, 1.16 M parameters. Dynamic input [1,3,H,W] (H and W multiples of 32); the output is a
probability map and boxes are recovered with the original DB unclip post-processing.
Models
| id | version | file | size | description |
|---|---|---|---|---|
db_ppocrv5_khmer_v1 |
v1 | textdet/db_v1.onnx |
4.8 MB | DB PP-OCRv5 mobile, Khmer fine-tuned v1 |
db_ppocrv5_orig |
v0 | textdet/db_ppocrv5_orig.onnx |
4.8 MB | DB PP-OCRv5 mobile (original) |
db_ppocrv5_khmer_v2 (default) |
v2 | textdet/db_v2.onnx |
4.8 MB | DB PP-OCRv5 mobile v2 (docs + exam sheets + handwriting) |
db_ppocrv5_orig.onnx is the unmodified PaddleOCR PP-OCRv5 mobile detector (Apache-2.0), included as the baseline and not trained by us.
db_v1.onnx is the first Khmer fine-tune on synthetic Khmer pages + real Khmer PDF pages + DocLayNet.
How db_v2.onnx (default) was trained
det/train_textdet.py (in the older Khm-Dataset-Creation repo) converts the original ONNX detector to PyTorch (onnx2torch) and
fine-tunes the probability map with DB shrunk kernels (ratio 0.4), then exports back to ONNX with the same input/output contract.
- 20,000 iterations, batch 16,
--robustaugmentation (scan/photo degradation), initialised from thetextdet_robustcheckpoint of v1. - Loss weights per source: synthetic 0.45, Khmer PDF 0.20, DocLayNet 0.35. Evaluation every 2,500 iterations.
- Dataset
textdet_v2: synthetic 15,000 train / 750 val docgen pages (v2 documents + exam sheets + handwriting lines, line quads tight to the ink); real DocLayNet 6,895 train / 647 val pages with line boxes from the PDF text layer; real Khmer PDF pages 548 train / 173 val. - Final F1: synthetic 0.894, DocLayNet 0.880 (0.833 low-res), Khmer PDF 0.697 (0.690 low-res); mean 0.799.
Training data and licences
| data | type | licence |
|---|---|---|
| docgen v2 / exam synthetic pages and handwriting lines | synthetic | generated |
| DocLayNet v2 | real | CDLA-Permissive 1.0 |
| Real Khmer PDF pages (government / NGO PDF crawl) | real | research use |
Base model: PaddleOCR PP-OCRv5 mobile detector (Apache-2.0). Because part of the fine-tuning data is research-use only,
the licence field is other: check that your use fits those terms. The owner's private exam photos were never used for training.
Part of ThaOCR
ThaOCR is a five-stage Khmer + English document OCR pipeline (layout, text-line detection, line recognition, font classification, page structure). Every model is plain ONNX (opset 17) and runs with onnxruntime on CPU. There is one repo per stage:
| stage | repo |
|---|---|
| layout | Thareah/ThaOCR-layout |
| textdet | Thareah/ThaOCR-textdet (this repo) |
| rec | Thareah/ThaOCR-rec |
| font | Thareah/ThaOCR-font |
| structure | Thareah/ThaOCR-structure |
The index repo Thareah/ThaOCR-models holds the full models.json manifest for all five stages.
models.textdet.json in this repo lists only this stage. The file and vocab paths in both are relative to a folder into which
all stage repos are downloaded together, for example hf download Thareah/ThaOCR-textdet --local-dir ThaOCR.
The pre/post-processing (letterbox + NMS, DB unclip, width bucketing + CTC, ...) is small numpy/OpenCV code in the
ThaOCR backend (backend/app/services/stages/).