ThaOCR β€” Khmer + English document OCR for CPU, browser and phone (ONNX)

Six small ONNX models that turn a photo or scan of a document into an editable document: text, headings, lists, tables, fonts and reading order, for Khmer (αžαŸ’αž˜αŸ‚αžš) and English. Every model is plain ONNX (opset 17) and runs with onnxruntime on a laptop CPU, in the browser (ONNX Runtime Web) or on a phone. No GPU is needed.

A phone photo of a Khmer ministry statement, the structure the models found on it, and the rebuilt editable document

Left: a phone photo, 905 Γ— 1280 px. Middle: what the models found, 13 blocks with a role each and 28 text lines. Right: the rebuilt document. On a laptop CPU this page took 1.71 s; mean reading confidence 97.9%.

  • Two detectors find where things are: page regions (text, title, list, table, stamp, logo and 16 more classes) and every single text line.
  • One recogniser reads each line: Khmer, English, digits and punctuation in the same model, print and handwriting, also under official stamps.
  • Three small models rebuild the document: the typeface and size of each line, the role and reading order of each line, and the rows and columns of tables.
  • Small: 55.7 MB for all six models, 41.4 MB with the int8 recogniser.

Every figure on this page is real output. The worked example is a photo of a public statement of the Ministry of Foreign Affairs and International Cooperation of Cambodia, traced through the pipeline on a laptop CPU. The table example is a scanned table from the ICDAR 2013 table competition, a set the models were never trained on.

Click any figure to open it full size.

Contents: Quick start Β· Model zoo Β· Pipeline Β· 1 Layout Β· 2 Text lines Β· Rules Β· 3 Recogniser Β· 4 Font Β· 5 Structure Β· 6 Table Β· Document Β· More examples Β· Speed and size Β· Limitations Β· Versions Β· Training history Β· Datasets Β· Licence

Quick start

Download the whole set, so the relative paths in models.json resolve:

pip install -U huggingface_hub onnxruntime numpy opencv-python
hf download Thareah/ThaOCR-models --local-dir ThaOCR

Read one cropped text line with the recogniser. This snippet was run against the files in this repo and returns the same text as the full pipeline:

import json, cv2, numpy as np, onnxruntime as ort
from huggingface_hub import hf_hub_download

repo = "Thareah/ThaOCR-models"
model = hf_hub_download(repo, "rec/crnn_m_v3_owner.onnx")
vocab = json.load(open(hf_hub_download(repo, "rec/crnn_m_v3_owner.vocab.json"), encoding="utf-8"))["itos"]
sess = ort.InferenceSession(model)

def read_line(path):
    g = cv2.imread(path, cv2.IMREAD_GRAYSCALE)                  # one text line, already cut out
    w = max(16, round(g.shape[1] * 48 / g.shape[0]))
    g = cv2.resize(g, (w, 48), interpolation=cv2.INTER_AREA)    # height 48, width follows
    x = ((g.astype(np.float32) / 255 - 0.5) / 0.5)[None, None]  # [1, 1, 48, W], values -1..1
    ids = sess.run(None, {"image": x})[0][:, 0].argmax(-1)      # [T] best symbol per time step
    return "".join(vocab[i] for k, i in enumerate(ids) if i != 0 and (k == 0 or i != ids[k - 1]))

print(read_line("line.png"))

A full page goes through layout, text-line detection, recognition, font and structure in that order. models.json is the manifest the ThaOCR backend reads: file / vocab are relative to the root of this repo. Pre- and post-processing (letterbox + NMS, DB unclip, width bucketing + CTC) is small NumPy / OpenCV code in the ThaOCR backend (backend/app/services/stages/).

With the backend running, one request does the whole page:

curl -F "files=@page.jpg" http://localhost:8010/process
# β†’ pages[0].blocks     regions and lines
#   pages[0].document   headings, lists, tables
#   pages[0].timings    milliseconds per stage

The browser app needs no installation: it downloads the models from this repo once, caches them, and runs everything on the device.

Model zoo

The default set of the server, documented on this page:

Stage Model Architecture Β· size Headline result
1 Layout layout_yolo11n_v3_22cls YOLO11 nano Β· 2.61 M Β· 10.9 MB mAP50-95 0.843, 22 classes
2 Text lines db_ppocrv5_khmer_v2 DB, PP-OCRv5 mobile Β· 1.17 M Β· 4.8 MB F1 0.877 on real Khmer PDF pages
3 Recogniser crnn_m_v3_owner (int8) CRNN + CTC Β· 4.76 M Β· 19.1 MB (int8 4.8 MB) CER 0.23 % printed Khmer Β· 0.84 % real English Β· 12.8 % real handwriting
4 Font font_cnn_v2 8-conv CNN Β· 0.48 M Β· 1.9 MB family 92.3 %, size within 10 % on 97.7 %
5 Structure struct_v3_tab Transformer, 6 layers Β· 2.04 M Β· 8.2 MB role accuracy 99.7 %
6 Table tsr_yolo11n_mix YOLO11 nano Β· about 2.6 M Β· 10.8 MB mAP50 0.836, 5 classes

Clean printed text is the strong case. Handwriting and noisy scans are harder; see Limitations. The browser app ships a slightly different default set (layout V4, structure V1, no table model, 41 MB).

All versions in this repo

Click a version to open its file. Bold = the default of the browser app. The server set documented above uses layout V3, structure V3 + tables and the table-structure model instead.

model what it does versions
Layout finds the regions of a page (text, title, table, figure, stamp, signature…) V1 Β· V2 Β· V2 nano Β· V3 Β· V4 Β· V4 int8
Text detection finds every text line on the page Original Β· V1 Β· V2
Recognition reads the text of each line (Khmer + English) V1 Β· V2 Β· V2.1 Β· V2.2 Β· V2.3 Β· V2.4 Β· V3
Font tells the font family, weight, slant and size of each line V1 Β· V2
Structure gives each line its role, paragraph, list level and reading order; v3 also tells document vs sheet and groups table lines into rows/columns/cells V1 Β· V3 pre Β· V3 + tables
Table structure finds rows, columns, header and spanning cells inside a table crop V3 pre Β· V3

Pipeline

The models run in a fixed order. Each one is a separate file named in models.json, so any stage can be swapped without touching code.

Model chain: photo, layout detector, text-line detector, line recogniser, font classifier, structure model, document; the table model branches off for table regions

All 17 steps on the example page. Models are in bold; everything else is a hand-written rule.

# Step Kind What it did on the example page Time
1 Decode the upload rule Alpha on white, 8-bit, long side capped, EXIF rotation. Stored at 905 Γ— 1280.
2 Layout detector model Letterboxed to 1024 Γ— 1024. 21,504 candidate boxes, 146 above 0.3, 23 after suppression. 116.7 ms
3 Region clean-up rule Drops page-sized figures and near-duplicates. 0 dropped, 23 kept.
4 Ruled-table finder rule Looks for a grid of ruled lines the layout model missed. None on this page. 9.8 ms
5 Stamp finder rule Red ink confirms 1 stamp. A copy of the page with the stamp faded is kept for reading. 5.1 ms
6 Text-line detector model Page resized to 1120 Γ— 1600: 28 line boxes. 5 more passes inside the emblem and the stamp added nothing. 722.0 ms
7 Lines into regions rule Each line joins the region that contains it. 3 lines had no region and became 1 new block.
8 Ink mask, snapping, bullets rule 27 line boxes and 2 picture boxes tightened to the ink. 6.4 ms
9 Line recogniser model 28 crops scaled to 48 px high, in 4 batches grouped by width. 600.4 ms
10 Bold check by stroke width rule Stroke thickness per word. Bold words: 4. 3.0 ms
11 Font classifier model 28 lines for family and size, then 97 single words for the weight head. 206.3 ms
12 Post-correction rule Optional text fixer, switched off. 0.0 ms
13 Marker and decoration rules rule List markers split from the text; ornaments and rule lines found: 2; the emblem relabelled from figure to logo. 22.3 ms
14 Structure model model 28 lines in; role, level, paragraph start and next line out. 9 blocks put in reading order. 3.6 ms
15 Table stage model Page kind "document" at 100.0%. No table block, so the table model was not called. 3.1 ms
16 Font sizes, colours, margins rule Sizes grouped into 3 levels: 12.7, 15.9, 18.6 px. Body family Khmer OS Siemreap.
17 Document builder rule 11 elements: header row, headings, paragraphs, the stamp picture and a footer row.

Steps without a time are counted in the step above. Whole page: 1.71 s.

1. Layout detector

layout_yolo11n_v3_22cls looks at the whole page once and proposes boxes, each with one of 22 classes. It tells the rest of the pipeline what is text to read and what is a picture to keep.

Architecture YOLO11 nano (Ultralytics), 23 layers, anchor-free, three detection heads
Parameters / file 2,609,986 Β· 10.9 MB ONNX
Input [1, 3, 1024, 1024], RGB Γ· 255, letterboxed with grey padding
Output [1, 26, 21504]: box centre, width, height + 22 class scores per candidate
Post-processing score β‰₯ 0.3, class-aware non-maximum suppression at IoU 0.5, in NumPy
Classes (22) text, title, section_header, list, table, figure, caption, header, footer, page_number, footnote, formula, signature, stamp, logo, qr_code, barcode, photo, handwriting, checkbox, form_field, decoration

Architecture

YOLO11 nano: backbone, top-down and bottom-up neck, three detection heads

Each band is one resolution. The backbone (left) shrinks the image five times. The neck carries deep features back up to finer resolutions, then down again, so every head sees both detail and context. Numbers in front of a block are the layer indices of the real network; the line under each Detect head is what it found on the example page. The three heads are joined into one tensor: 16,384 + 4,096 + 1,024 = 21,504 candidates.

Results

Model File CPU, 4 threads Precision Recall mAP50 mAP50-95
YOLO11s, round 2 (retired) 38.2 MB 179 ms 0.947 0.930 0.963 0.835
YOLO11n V2 10.9 MB 70.5 ms 0.941 0.910 0.956 0.798
YOLO11n V3 (this model) 10.9 MB about 70 ms 0.958 0.946 0.973 0.843
YOLO11n V4 (browser default) 10.9 MB about 70 ms 0.960 0.956 0.974 0.847

Each row is scored on that run's own validation set. Scored on one shared set, the 1,100-page V3 validation set, the models are level: YOLO11s 0.847 against V3 0.843, and in a later run V3 0.848 against V4 0.845 (mAP50-95). The nano model is a quarter of the size and more than twice as fast, so it became the default.

On a real page

21,504 candidate boxes β†’ 146 above 0.3 β†’ 23 after suppression β†’ 23 regions kept.

Network input and the score map of each of the three detection heads

All three heads fire on a real page: stride 8 has 10 cells above 0.3 (peak 0.733), stride 16 has 47 (peak 0.889), stride 32 has 89 (peak 0.888).

All candidates before suppression, and the final regions numbered by score

The strongest regions (the full list has 23):

Region Class Score x, y width Γ— height
1 footer 0.889 38, 1204 223 Γ— 68
2 stamp 0.887 444, 914 192 Γ— 185
3 footer 0.839 641, 1203 220 Γ— 62
4 text 0.789 246, 395 426 Γ— 29
5 text 0.788 191, 452 602 Γ— 34
6 decoration 0.733 398, 215 98 Γ— 12
7 text 0.731 307, 362 307 Γ— 29
8 text 0.720 128, 553 666 Γ— 35

Most text regions are single lines, which the model proposes one by one and the pipeline later merges into paragraphs. The emblem is found as a figure at a low score; a position rule later relabels it as the logo.

2. Text-line detector

db_ppocrv5_khmer_v2 finds every text line as a rotated box. It does not draw boxes directly: it paints a map of how likely each pixel is to be the core of a line, and simple geometry turns that map into boxes.

Architecture DB (Differentiable Binarization) with the PP-OCRv5 mobile backbone, feature pyramid and upsampling head
Parameters / file 1,171,601 weights in the ONNX file Β· 4.8 MB
Input [N, 3, H, W], BGR, ImageNet mean and std; page resized so the long side is 1600–2200 px, sides multiples of 32
Output [N, 1, H, W] probability map
Post-processing threshold 0.3 β†’ connected blobs β†’ rotated rectangle β†’ keep mean β‰₯ 0.5 β†’ grow by area Γ— 1.6 Γ· perimeter

Architecture

DB text detector: depthwise backbone, four levels fused top-down, joined, upsampled to a full-size probability map

Sizes on the left are for the example page. Four backbone levels are squeezed to 96 channels, mixed top-down, reduced to 24 channels each, brought to one size and joined. Two transposed convolutions bring the map back to full resolution, and a sigmoid turns it into probabilities. The network is trained to paint shrunk line kernels, so neighbouring lines never touch.

Results (F1 at IoU 0.5, 100 held-out pages per set)

Set V1 V2 (this model)
Generated pages and exam sheets 0.806 0.923
Real Khmer PDF pages 0.865 0.877
Real DocLayNet pages (English) 0.886 0.877

The unmodified PP-OCRv5 mobile detector scored 0.694 on real Khmer PDF pages in the first evaluation round, where V1 scored 0.860.

On a real page

1120 Γ— 1600 probability map β†’ 7.6% of the pixels above 0.3 β†’ 48 blobs β†’ 28 line boxes.

Probability map, thresholded mask and the resulting line boxes

Close-up: the kernel the network painted inside each line, and the box after growing it

After the page pass the detector checks how much glyph-sized ink lies inside its boxes (96.8% here; below 60% it retries at a larger scale). Pictures get their own passes, because an emblem or a stamp often hides text:

Pass Where Crop, px Network input
1 whole page 905 Γ— 1280 1120 Γ— 1600
2 emblem 129 Γ— 126 256 Γ— 256
3 emblem 234 Γ— 201 480 Γ— 416
4 stamp area, on the copy with the stamp faded 295 Γ— 299 576 Γ— 608
5 stamp area, on the copy with the stamp faded 295 Γ— 299 736 Γ— 736
6 stamp area, on the copy with the stamp faded 295 Γ— 299 896 Γ— 896

On this page the extra passes found nothing new.

Rules between the models

No neural network here. These steps connect the two detectors and clean up the page before anything is read.

Stamp close-up: the photo, the red-ink mask, and the working copy with the stamp faded

The layout model finds the stamp; the rule checks for red ink inside it. Inside the stamp the red channel is stretched so the stamp fades and the black text stays. The detector and the recogniser read this working copy.

The ink mask, and lines matched to layout regions then snapped to the ink

Rule What it does On this page
Stamp finder marks stamps by red ink, adds any the layout model missed, fades them on a working copy 1 stamp confirmed, 0 added
Ruled-table finder searches the ink mask for crossing horizontal and vertical rules no grid
Lines into regions each line joins the region that contains its centre 25 assigned, 3 without a region
Merge paragraphs single-line regions stacked with the same edges become one block 23 regions became 13 blocks
Snap boxes to ink grows a box until it no longer cuts through a glyph 27 of 28 lines, 2 pictures
Decorations and rule lines ornaments and long ruled lines become picture elements, not text 2 found
Bold words stroke thickness per word, then the font model's weight head per word 4 bold words of 97 checked

3. Line recogniser

crnn_m_v3_owner reads one text line at a time. The line is cut out, straightened, turned grey and scaled to 48 pixels high. The model moves left to right in small time steps and outputs one symbol or a blank per step.

Architecture CRNN: 7 convolutions, 4 poolings, 2-layer bidirectional LSTM (256 each way), CTC output
Parameters / file 4,763,795 Β· 19.1 MB fp32 Β· 4.8 MB int8 (for phones)
Input [N, 1, 48, W], grey, (x Γ· 255 βˆ’ 0.5) Γ· 0.5, W from 16 to 4,200
Output [T, N, 195] scores, T = W Γ· 4, index 0 is the CTC blank
Alphabet 194 symbols: Khmer consonants, vowels and signs, Khmer and Latin digits, ASCII letters and punctuation, Β« Β» β€’ Β°
Decoding greedy: best symbol per step, merge repeats, drop blanks; confidence = mean probability of the emitted symbols

Architecture

CRNN: convolutions and poolings, columns to a sequence, two bidirectional LSTM layers, CTC decoding

The first two pools halve height and width. The last two halve only the height, so one output step always covers 4 pixel columns of the 48-pixel-high line. That fine time resolution matters for narrow Khmer clusters.

Results (character error rate, lower is better)

Test set Lines V2.3 V3 (this model) V3 int8
Real handwritten Khmer exam lines, held out by page 434 20.73 % 12.83 % 12.98 %
Real English lines (DocLayNet test) 3,000 0.88 % 0.84 % 0.84 %
Real Khmer signboard crops (spaces ignored) 5,171 12.56 % 12.59 % –
Printed Khmer, validation – 0.216 % 0.225 % –
Real Khmer handwriting, Thareah validation – 21.53 % 17.76 % –
Real Khmer handwriting, SoyVitou validation – 9.95 % 8.33 % –

V3 gained on handwriting without losing on print. On signboards the error grows with letter size: about 8 % below 36 px and 18 % above 60 px.

On a real page

28 line crops β†’ 4 batches grouped by width β†’ 4,251 time steps, 58% of them blanks β†’ mean confidence 97.9%.

Four lines of the page: the crop, the grey network input, the symbol emitted at each time step and the confidence per step

How to read a card: the top strip is the crop from the page, the grey strip is what the network received. Under it, each character sits at the time step where the model emitted it. Tall bars are symbols, the flat baseline is the CTC blank.

All 28 lines as the model read them
Line Recognised text Confidence
1 αž–αŸ’αžšαŸ‡αžšαžΆαž‡αžΆαžŽαžΆαž…αž€αŸ’αžšαž€αž˜αŸ’αž–αž»αž‡αžΆ 95.7%
2 αž‡αžΆαžαž· αžŸαžΆαžŸαž“αžΆ αž–αŸ’αžšαŸ‡αž˜αž αžΆαž€αŸ’αžŸαžαŸ’αžš 96.5%
3 αž€αŸ’αžšαžŸαž½αž„αž€αžΆαžšαž”αžšαž‘αŸαžŸ 93.9%
4 αž“αž·αž„αžŸαž αž”αŸ’αžšαžαž·αž”αžαŸ’αžαž·αž€αžΆαžšαž’αž“αŸ’αžαžšαž‡αžΆαžαž· 97.5%
5 αž›αŸαžαŸ– αžαž€ ្៦/្០្αŸ₯ αž€αž”αž‘.សធ 99.8%
6 αžŸαŸαž…αž€αŸ’αžαžΈαžαŸ’αž›αŸ‚αž„αž€αžΆαžšαžŽαŸαžšαž”αžŸαŸ‹αž’αŸ’αž“αž€αž“αžΆαŸ†αž–αžΆαž€αŸ’αž™ 97.6%
7 αž€αŸ’αžšαžŸαž½αž„αž€αžΆαžšαž”αžšαž‘αŸαžŸ αž“αž·αž„αžŸαž αž”αŸ’αžšαžαž·αž”αžαŸ’αžαž·αž€αžΆαžšαž’αž“αŸ’αžαžšαž‡αžΆαžαž· 96.9%
8 αž†αŸ’αž›αžΎαž™αžαž”αž“αžΉαž„αž€αžΆαžšαžŸαžΆαž€αžŸαž½αžšαžšαž”αžŸαŸ‹αž’αŸ’αž“αž€αžŸαžΆαžšαž–αŸαžαŸŒαž˜αžΆαž“ αž’αŸ†αž–αžΈαž€αžΆαžšαž•αŸ’αžŸαž–αŸ’αžœαž•αŸ’αžŸαžΆαž™αž€αŸ’αž“αž»αž„αž”αžŽαŸ’αžαžΆαž‰αžŸαž„αŸ’αž‚αž˜αžαŸ’αž˜αžΈαŸ— 99.9%
9 αž“αŸαŸ‡αžŠαŸ‚αž›αžαžΆ αžœαŸ€αžαžŽαžΆαž˜αž€αŸ†αž–αž»αž„αžαŸ‚αž’αž“αž»αžœαžαŸ’αžαž“αžΌαžœαž‚αž˜αŸ’αžšαŸ„αž„αžŸαžΆαž„αžŸαž„αŸ‹αž•αŸ’αž›αžΌαžœαž€αžΆαžαŸ‹αžŸαž˜αž»αž‘αŸ’αžš αž—αŸ’αž‡αžΆαž”αŸ‹αž–αžΈαž€αŸ„αŸ‡αž‘αŸ€αž“αž αŸƒ 97.5%
10 (Tien Hai) αž“αŸƒαžαŸαžαŸ’αžαž’αžΆαž“αž™αŸ‰αžΆαž„ (An Giang) αž‘αŸ…αž€αžΆαž“αŸ‹αž€αŸ„αŸ‡αž αŸ’αžœαžΌαž‚αž€αŸ‹ (αž€αŸ„αŸ‡αžαŸ’αžšαž›αŸ‹) αž•αŸ’αž‘αž»αž™αž“αžΉαž„αž€αž·αž…αŸ’αž…αž–αŸ’αžšαž˜αž–αŸ’αžšαŸ€αž„ 97.7%
11 αžŠαŸ‚αž“αž‘αžΉαž€αž”αŸ’αžšαžœαžαŸ’αžαž·αžŸαžΆαžŸαŸ’αžαŸ’αžšαž€αž˜αŸ’αž–αž»αž‡αžΆ-αžœαŸ€αžαžŽαžΆαž˜ αž†αŸ’αž“αžΆαŸ†αŸ‘αŸ©αŸ¨αŸ’ αž’αŸ’αž“αž€αž“αžΆαŸ†αž–αžΆαž€αŸ’αž™αž€αŸ’αžšαžŸαž½αž„αž€αžΆαžšαž”αžšαž‘αŸαžŸ αž“αž·αž„αžŸαž - 99.1%
12 αž”αŸ’αžšαžαž·αž”αžαŸ’αžαž·αž€αžΆαžšαž’αž“αŸ’αžαžšαž‡αžΆαžαž· αžŸαžΌαž˜αž’αŸ’αžœαžΎαž€αžΆαžšαž”αŸ†αž—αŸ’αž›αžΊαžαžΆ αžαžΆαž˜αž€αžΆαžšαž”αž‰αŸ’αž‡αžΆαž€αŸ‹αž–αžΈαž―αž€αž§αžαŸ’αžαž˜αž―αž€αž’αž‚αŸ’αž‚αžšαžŠαŸ’αž‹αž‘αžΌαžαžœαŸ€αžαžŽαžΆαž˜ αž“αž·αž„ 98.8%
13 αž–αŸαžαŸŒαž˜αžΆαž“αž•αŸ’αžαž›αŸ‹αžŠαŸ„αž™αžŸαŸ’αžαžΆαž“αž‘αžΌαžαžœαŸ€αžαžŽαžΆαž˜αž“αŸ…αž—αŸ’αž“αŸ†αž–αŸαž‰ αž‚αžΊαž–αž»αŸ†αž˜αžΆαž“αž€αžΆαžšαžŸαžΆαž„αžŸαž„αŸ‹αž•αŸ’αž›αžΌαžœαž€αžΆαžαŸ‹αžŸαž˜αž»αž‘αŸ’αžšαžšαŸ†αž›αŸ„αž—αž“αžΉαž„ 98.1%
14 αž€αž·αž…αŸ’αž…αž–αŸ’αžšαž˜αž–αŸ’αžšαŸ€αž„αžšαžœαžΆαž„αž”αŸ’αžšαž‘αŸαžŸαž‘αžΆαŸ†αž„αž–αžΈαžš αžŠαžΌαž…αž€αžΆαžšαž•αŸ’αžŸαž–αŸ’αžœαž•αŸ’αžŸαžΆαž™αž›αžΎαž”αžŽαŸ’αžαžΆαž‰αžŸαž„αŸ’αž‚αž˜αž“αŸ„αŸ‡αž‘αŸαŸ” 98.3%
15 αžšαžΌαž”αž—αžΆαž–αžŸαŸ†αžŽαž„αŸ‹αž•αŸ’αž›αžΌαžœαž€αžΆαžαŸ‹αžŸαž˜αž»αž‘αŸ’αžš αžŠαŸ‚αž›αžƒαžΎαž‰αž…αŸ‚αž€αž•αŸ’αžŸαž–αŸ’αžœαž•αŸ’αžŸαžΆαž™αž“αŸ…αž€αŸ’αž“αž»αž„αž”αžŽαŸ’αžαžΆαž‰αžŸαž„αŸ’αž‚αž˜ αž‚αžΊαž‡αžΆ 98.6%
16 αžŸαŸ†αžŽαž„αŸ‹αž•αŸ’αž›αžΌαžœαž…αŸαž‰αž–αžΈαžŠαžΈαž‚αŸ„αž€αž“αŸƒαžŸαž„αŸ’αž€αžΆαžαŸ‹αž αžΆαž‘αŸ€αž„ (Ha Tien) αžαŸαžαŸ’αžαž’αžΆαž“αž™αŸ‰αžΆαž„ (An Giang) αž‘αŸ…αž€αžΆαž“αŸ‹ 99.1%
17 αž€αŸ†αž–αž»αž„αž•αŸ‚αž–αž αž»αž”αŸ†αžŽαž„αž“αŸƒαž‘αžΈαž€αŸ’αžšαž»αž„αž αžΆαž‘αŸ€αž„ αžŠαŸ‚αž›αžŸαŸ’αžαž·αžαž€αŸ’αž“αž»αž„αž‘αžΉαž€αžŠαžΈαžœαŸ€αžαžŽαžΆαž˜αŸ” 99.4%
18 αž€αŸ’αžšαžŸαž½αž„αž€αžΆαžšαž”αžšαž‘αŸαžŸ αž“αž·αž„αžŸαž αž”αŸ’αžšαžαž·αž”αžαŸ’αžαž·αž€αžΆαžšαž’αž“αŸ’αžαžšαž‡αžΆαžαž· αžŸαžΌαž˜αžŸαŸ’αž“αžΎαž±αŸ’αž™αž”αž‰αŸ’αžˆαž”αŸ‹αž€αžΆαžšαž…αŸ‚αž€αž•αŸ’αžŸαžΆαž™αž–αŸαžαŸŒαž˜αžΆαž“ 96.9%
19 αžαž»αžŸαž€αžΆαžšαž–αž·αžαž“αŸαŸ‡ αžŠαŸ‚αž›αž’αžΆαž…αž”αž„αŸ’αž€αž±αŸ’αž™αž˜αžΆαž“αž€αžΆαžšαž™αž›αŸ‹αžαž»αžŸ αž“αž·αž„αž’αŸ’αžœαžΎαž±αŸ’αž™αž”αŸ‰αŸ‡αž–αžΆαž›αŸ‹αžŠαž›αŸ‹αž‘αŸ†αž“αžΆαž€αŸ‹αž‘αŸ†αž“αž„αž˜αž·αžαŸ’αžαž—αžΆαž–αžšαžœαžΆαž„ 99.2%
20 αž–αŸ’αžšαŸ‡αžšαžΆαž‡αžΆαžŽαžΆαž…αž€αŸ’αžšαž€αž˜αŸ’αž–αž»αž‡αžΆ αž“αž·αž„αžŸαžΆαž’αžΆαžšαžŽαžšαžŠαŸ’αž‹αžŸαž„αŸ’αž‚αž˜αž“αž·αž™αž˜αžœαŸ€αžαžŽαžΆαž˜αŸ” 98.7%
21 αžαŸ’αž„αŸƒαž…αž“αŸ’αž‘ αŸ€αž€αžΎαž αžαŸ’αž‰αŸ‚αž˜αž·αž‚αžŸαž·αžš αž†αŸ’αž“αžΆαŸ†αž˜αŸ’αžŸαžΆαž‰αŸ‹ αžŸαž”αŸ’αžαžŸαŸαž€ αž–.ស. ្αŸ₯៦៩ 97.0%
22 αžšαžΆαž‡αž’αžΆαž“αžΈαž—αŸ’αž“αŸ†αž–αŸαž‰αžαŸ’αž„αŸƒαž‘αžΈαŸ’αŸ€ αžαŸ‚αžœαž·αž…αŸ’αž†αž·αž€αžΆ αž†αŸ’αž“αžΆαŸ†αŸ’αŸ αŸ’αŸ₯ 95.9%
23 αž’αžΆαžŸαž™αžŠαŸ’αž‹αžΆαž“: αž›αŸαž ៣ វិថី αžŸαž˜αŸ’αžαŸαž… αž αŸŠαž»αž“ αžŸαŸ‚αž“ 96.9%
24 αž‘αžΌαžšαžŸαŸαž–αŸ’αž‘ : (855) 23 216 122 98.1%
25 αžŸαž„αŸ’αž€αžΆαžαŸ‹αž‘αž“αŸ’αž›αŸαž”αžΆαžŸαžΆαž€αŸ‹ αžαŸαžŽαŸ’αžŒαž…αŸ†αž€αžΆαžšαž˜αž“ 98.8%
26 αž‘αžΌαžšαžŸαžΆαžš : (855) 23 216 141, 023 213 341 99.5%
27 αžšαžΆαž‡αž’αžΆαž“αžΈαž—αŸ’αž“αŸ†αž–αŸαž‰ αž–αŸ’αžšαŸ‡αžšαžΆαž‡αžΆαžŽαžΆαž…αž€αŸ’αžšαž€αž˜αŸ’αž–αž»αž‡αžΆ 98.6%
28 αž’αŸŠαžΈαž˜αŸ‰αŸ‚αž› : mfaic@mfaic.gov.kh 97.5%

There is no typed reference for this photo, so accuracy here is by eye: the text reads correctly almost everywhere. One error is visible: in line 21, which runs through the stamp, the model read αžαŸ’αž‰αŸ‚ where the page says αžαŸ‚. The lowest line confidence on the page is 93.9%.

4. Font classifier

font_cnn_v2 names the typeface of each line, says whether it is bold or italic, and estimates the font size, so the rebuilt document looks like the original. Long lines are cut into three windows and the answers are averaged.

Architecture FontNet: 4 blocks of two 3Γ—3 convolutions (24, 48, 96, 144 channels), mean + max pooling, 4 linear heads
Parameters / file 483,034 Β· 1.9 MB ONNX, label lists stored in the file's metadata
Input [N, 1, 32, 256], grey, (x Γ· 255 βˆ’ 0.5) Γ· 0.5
Outputs family [N, 29] Β· weight [N, 2] Β· slant [N, 2] Β· size [N, 1] (em ratio; font px = ratio Γ— crop height)
Families (29) 12 Khmer OS faces, Noto Sans / Serif Khmer, Khmer Digital, Hanuman, Kantumruy Pro, Nokora, Odor Mean Chey, Chenla, Preahvihear, Suwannaphum, Koulen, Dangrek, Bayon, Angkor, Taprom, Latin serif, Latin sans

Architecture

FontNet: four convolution blocks, mean and max pooling joined, four linear heads

Results (8,000 held-out synthetic crops)

Metric V1 V2 (this model)
Family accuracy, 29 classes 92.3 % 92.3 %
Weight accuracy (regular / bold) 97.7 % 97.8 %
Slant accuracy (upright / italic) 99.98 % 99.9 %
Font size, median relative error – 1.8 %
Font size within 10 % – 97.7 %

Display faces and Latin faces are right 95–100 % of the time. Body faces that share a design are confused with each other: Khmer OS (33.6 %) and Khmer OS System (55.1 %) are the weak pair.

On a real page

Four lines of the page: the 32 Γ— 256 windows the model saw and its top typeface guesses, weight, slant and size

Typeface chosen Lines Mean confidence Mean size
Khmer OS Siemreap 16 91% 18.7 px
Khmer OS Muol Light 6 95% 17.1 px
Noto Serif Khmer 5 51% 12.8 px
Latin serif 1 57% 13.8 px

The body and the letterhead are recognised with high confidence. The small footer print is less certain: at 12 px a serif Khmer face has few pixels to tell it from its neighbours.

5. Structure model

struct_v3_tab decides what each line is and where it belongs: its role (title, text, list item, header, footer and so on), its list level, whether it starts a paragraph, and which line comes next. It never sees pixels, only a row of numbers per line.

Architecture StructureNet: Transformer encoder, 6 layers, width 192, 6 heads, feed-forward 384, pre-norm
Parameters / file 2,039,677 Β· 8.2 MB ONNX
Inputs feats [1, N, 39] (position, size, gaps, script mix, bold, marker, neighbours) Β· chars [1, N, 6] (first 3 and last 3 characters, hashed into 2,047 buckets) Β· N ≀ 256 lines
Outputs (8) role [N, 12] Β· paragraph start [N, 2] Β· level [N, 4] Β· marker [N, 2] Β· next-line pointer [N, N+1] Β· page kind [3] Β· in-table [N, 2] Β· pair relations [N, N, 3]
Roles (12) text, title, section_header, list_item, caption, header, footer, page_number, footnote, table, form_field, other

Architecture

StructureNet: line features and character ids embedded and added, six Transformer encoder layers, eight output heads

Every line attends to every other line, so a line can be judged by its neighbours. Reading order is a pointer network: line i scores every other line and an end-of-page token as its successor (a dot product of two projections plus a small network on the pair's geometry). Decoding starts at the line nobody points to and follows the best unused successor. The table heads add a page kind, an in-table probability per line, and for every pair of lines whether they share a row, a column or a cell.

Results (final epoch)

Metric Clean generated pages Photo-like pages through the real pipeline
Role accuracy 99.7 % 95.8 %
List level accuracy 99.97 % 88.6 %
Paragraph-start F1 0.998 0.939
Next-line accuracy 93.8 % 92.1 %
Reading order, Kendall's tau 0.883 0.944
Page kind accuracy 100 % –
In-table F1 Β· same-row F1 Β· same-column F1 Β· same-cell F1 1.000 Β· 0.836 Β· 0.982 Β· 0.689 –

On a real page

28 lines in, 28 Γ— 39 numbers, 8 output tensors.

The next-line pointer matrix of the example page and the decoded reading order drawn on the photo

On this page the model agreed with every role the layout model and the rules had proposed. Its work was the order: the layout model returns regions sorted by score, and the structure model put 9 blocks into reading order. In the two footer columns the pointer is ambiguous, and there the server keeps each column together instead.

6. Table structure detector

tsr_yolo11n_mix is a second YOLO11 nano that looks only at a table region and finds its rows, columns, header rows and merged cells. The text lines found earlier are then dropped into the grid.

Architecture YOLO11 nano, the same 23 layers as the layout detector
Parameters / file about 2.6 M Β· 10.8 MB ONNX
Input [1, 3, 800, 800]: the table box padded by 2 %, letterboxed
Output [1, 9, 13125] (grids of 100Β², 50Β² and 25Β² cells)
Classes (5) row, column, column_header, spanning_cell, projected_row_header
When it runs only on blocks classed as table, by the layout model or by the ruled-grid rule

Table structure detector: the same YOLO11 nano network at 800 Γ— 800 with five classes

Results

Validation (PubTables-1M, FinTabNet, TabRecSet and synthetic sheets together) Precision Recall mAP50 mAP50-95
tsr_yolo11n_mix, epoch 15 of 23 0.788 0.773 0.836 0.574

On a real table

The statement above has no table, so this model stayed idle there. This example is a scanned table from the ICDAR 2013 table competition, an evaluation-only set.

13,125 candidate boxes β†’ 115 above 0.3 β†’ 13 boxes after suppression (7 rows, 3 columns, 1 header band, 2 merged cells) β†’ a 7 Γ— 3 grid with 19 cells.

The scanned table and the rows, columns, header band and merged cells the model returned

The result as data, with 2 header rows and the merged cells kept:

Faculty clusterFemale students
SamplePopulation
Sciences63 (18.5%)597 (16.4%)
Social Sciences189 (55.6%)2075 (57.0%)
Humanities77 (22.6%)755 (20.7%)
Civil Sciences11 (3.2%)213 (5.9%)
Total3403640

All 19 cells were filled, read with a mean confidence of 98.4%. The whole page took 0.73 s, of which the table model 63 ms. The layout model proposed no region for this cropped table; the ruled-grid rule found it from its lines.

Document builder

The last step turns blocks and lines into a document: headings, paragraphs, lists with their markers, tables, pictures, header and footer, each with typeface, size and alignment. The Document view of the app and the Word export are made from it.

The photo beside the rebuilt document

More examples

Three more public documents, photographed and run through the same default set. Left: the photo with the detected blocks. Right: the rebuilt document, drawn by the app's own Document view.

English statement β€” 905 Γ— 1280 px Β· 21 lines Β· mean confidence 99.1% Β· 1.59 s

English ministry statement: photo with detected blocks, and the rebuilt document

Ministry notice with a list β€” 619 Γ— 876 px Β· 34 lines Β· mean confidence 97.8% Β· 1.74 s

Ministry notice with letterhead, numbered list and QR code: photo with detected blocks, and the rebuilt document

Royal decree β€” 920 Γ— 1280 px Β· 36 lines Β· mean confidence 98.4% Β· 2.84 s

Royal decree with emblem, reference list, articles, signature and gold seal: photo with detected blocks, and the rebuilt document

Speed and size

ONNX Runtime on a laptop CPU. No GPU is used anywhere.

Model, one call File 1 thread 4 threads
Layout, YOLO11n, one page at 1024 px 10.9 MB 185 ms 70.5 ms
Text lines, DB, one page at 1600–2200 px 4.8 MB 819 ms 370 ms
Recogniser fp32, one 48 Γ— 400 line 19.1 MB 34.1 ms 11.6 ms
Recogniser int8, one 48 Γ— 400 line 4.8 MB 100.8 ms 31.3 ms
Font classifier, one line 1.9 MB – about 1 ms
Structure model, one page 8.2 MB – 2 to 4 ms

The int8 recogniser is a quarter of the size but slower on this CPU; it exists for phones, where download size matters more.

Whole pages:

Page Pixels Lines Layout Text lines Recogniser Font Structure Table Total
Ministry statement, Khmer (worked example) 905 Γ— 1280 28 117 ms 722 ms 600 ms 206 ms 4 ms 3 ms 1.71 s
Scanned table 800 Γ— 241 19 118 ms 269 ms 171 ms 88 ms 0 ms 63 ms 0.73 s
Ministry statement, English 905 Γ— 1280 21 67 ms 431 ms 698 ms 330 ms 3 ms 3 ms 1.59 s
Ministry notice with a list 619 Γ— 876 34 70 ms 485 ms 754 ms 331 ms 9 ms 7 ms 1.74 s
Royal decree 920 Γ— 1280 36 70 ms 1558 ms 858 ms 273 ms 5 ms 4 ms 2.84 s

Limitations

  • Handwriting is not solved. Real Khmer handwriting is read at 13 % to 18 % character error, against 0.2 % for printed Khmer.
  • Unknown symbols. A glyph outside the 194-symbol alphabet is read as the nearest known one. Arrows, box-drawing characters and most emoji are not in it.
  • Text under stamps. Red stamps are faded before reading, but errors cluster there. On the example page the one visible error sits under the stamp.
  • No labelled real Khmer layout test set exists. Layout scores are measured on generated pages and public English sets; quality on real Khmer pages is judged by eye.
  • The structure model has only seen generated pages. On unusual real layouts the rules can do better, so the server lets the rules overrule it in specific cases.
  • Tables. The table model scores mAP50-95 0.57. Borderless tables depend on text alignment, and merged cells are the weakest part (same-cell F1 0.69 in the structure model).
  • Fonts. Only 29 families are known. Any other face is mapped to the nearest one, and Khmer OS is often confused with Khmer OS System.
  • Light text on dark backgrounds is read, but colour detection and the ink rules assume dark ink on light paper.

Versions

release git tag what is in it
recogniser v3 (2026-11-17) – adds crnn_m_v3_owner (fp32 + int8), v2.3 fine-tuned on real Khmer exam handwriting; the apps use it as the default recogniser
v3-tables (preview, 2026-11-14) – adds structure v3 (+ table heads) and the table-structure YOLO11n; models.json defaults unchanged
v3 (latest default set) v3 layout v4 (default, plus int8) Β· textdet v2 Β· rec v2.3 Β· font v2 Β· structure v1
v2 – first publication: layout v3 default, same textdet / rec / font / structure

All model files are in this one repo; download the latest commit (the v3 git tag points at an index-only commit without the weights).

Where the files are

Everything is in this one repo, one folder per stage, together with the full models.json manifest.

stage folder
layout layout/
textdet textdet/
rec rec/
font font/
structure structure/
table structure table/

Download the whole set so the relative paths in models.json resolve:

hf download Thareah/ThaOCR-models --local-dir ThaOCR
stage default model file size what it does
layout layout_yolo11n_v4_22cls (_int8: 3.3 MB, less exact) layout/layout_v4_n_22cls.onnx 10.9 MB 22 region classes: text, title, section_header, list, table, figure, caption, header, footer, page_number, footnote, formula, signature, stamp, logo, qr_code, barcode, photo, handwriting, checkbox, form_field, decoration. Input [1,3,1024,1024].
textdet db_ppocrv5_khmer_v2 textdet/db_v2.onnx 4.8 MB DB text-line detector (PP-OCRv5 mobile, fine-tuned for Khmer). Input [1,3,H,W], H and W multiples of 32.
rec crnn_m_v3_owner / _int8 rec/crnn_m_v3_owner*.onnx + .vocab.json 19 MB / 4.8 MB CRNN-CTC line recogniser, Khmer + English, 195 symbols, line height 48, dynamic width [N,1,48,W].
font font_cnn_v2 font/font_cnn_v2.onnx 1.9 MB per line: font family (29 Khmer/Latin families), weight, slant, em size. Input 32x256 grey.
structure struct_v1 structure/struct_v1.onnx 4.0 MB small Transformer over the page's lines: role, paragraph start, list level, bullet, reading order.

Older versions kept for comparison: layout v1 (YOLO11s, 12 classes; .onnx + .pt), layout v2 (YOLO11s round 2, 21 classes), v2 YOLO11n and v3 YOLO11n, textdet v1 and the original PP-OCRv5 detector, recogniser v1, v2, v2.1 (_hw), v2.2 (_stamp), v2.3 (_stamp2), v2.4 (_stamp3), font v1.

The table above is the default set of the browser app. models.json in this repo still names recogniser v2.3 as its default; both apps now use v3.

Training history

Layout detector (Ultralytics YOLO11, imgsz 1024, AdamW, cosine LR, mosaic 0.6, no horizontal flip)

  1. v1 β€” YOLO11s, 12 classes, trained in the earlier Khm-Dataset-Creation repo on synthetic Khmer pages, real Khmer PDF pages with heuristic labels and DocLayNet.
  2. v2 round 1 (layout_r1) β€” YOLO11s from v1 weights, 21-class taxonomy, 30 epochs (stopped at 26 by the time budget), lr0 1e-3, batch 8. Val mAP50 0.964, mAP50-95 0.834.
  3. v2 round 2 (layout_r2, layout_v2_r2_21cls.onnx) β€” continued from round 1 on the round-2 set (32,290 train / 923 val pages), lr0 5e-4. mAP50 0.962, mAP50-95 0.834.
  4. v2 nano (layout_v2_n_21cls.onnx) β€” YOLO11n (2.6 M params) from the COCO-pretrained yolo11n.pt on the same round-2 set, 31 epochs, lr0 2e-3, batch 16. mAP50 0.956, mAP50-95 0.798.
  5. v3 nano (layout_v3_n_22cls.onnx, server default) β€” fine-tune of v2 nano on layout_v3 (18,000 train / 1,100 val: 10,000 new docgen v3 pages with the decoration class + 8,000 pages replayed from round 2), 37 epochs, lr0 6e-4. mAP50 0.972, mAP50-95 0.842.
  6. v4 nano (layout_v4_n_22cls.onnx, browser default) β€” fine-tune of v3 nano on layout_v4 (14,027 train / 887 val pages: 9,000 new docgen v4 pages β€” Khmer government notices and letters with emblem letterheads and mottos, handwritten reference numbers and dates, label-value blocks, tables with spanning group rows, stamps printed over signatures and dates β€” + 5,027 pages replayed from layout_v3; 10,000 were planned, a file-name collision dropped the rest), 57 epochs in a 3 h budget, lr0 0.0003. On the v4 validation set: mAP50 0.974, mAP50-95 0.850 (v3 on the same set: 0.935 / 0.802). That set is mostly new-style v4 pages; on the v3 validation set the two are level (v3 0.848, v4 0.845 mAP50-95). Largest gains: handwriting 0.42 β†’ 0.75, header 0.70 β†’ 0.93, text 0.72 β†’ 0.87, stamp 0.76 β†’ 0.82, signature 0.66 β†’ 0.73 (mAP50-95). layout_v4_n_22cls_int8.onnx is the same network after onnxruntime dynamic weight quantisation (3.3 MB); boxes are visibly less tight on tables and forms, so the app does not pick it by default.

Layout training data (round 2 set): docgen v2 synthetic pages (12,000 Cambodian + US/English documents: letters, invoices, forms, ID cards, exam sheets, receipts, reports…), DocLayNet v2 (6,895 train / 647 val real pages, 11 classes + page_number, plus degraded scan/photo copies), real Khmer PDF pages with silver heuristic labels (548 train / 173 val, each also degraded), SignverOD signatures and stamp scans (round 3 of the v1 repo), D4LA real US scans (2,834 train, only form/invoice/letter/memo; missing classes filled by a teacher model, training/layout/pseudo_label.py), CommonForms (1,517 pages, checkbox boxes only), docgen exam answer sheets (3,000 pages). Taxonomy in training/taxonomy.py.

Text-line detector (DB, PP-OCRv5 mobile backbone, 1.16 M params)

det/train_textdet.py converts the original PP-OCRv5 mobile detector ONNX to PyTorch (onnx2torch) and fine-tunes the probability map with DB shrunk kernels (r = 0.4) so the original unclip post-processing still works.

  • v1 β€” fine-tuned on synthetic Khmer pages + real Khmer PDF pages + DocLayNet text-layer line boxes.
  • v2 (db_v2.onnx, default) β€” 30,000 iterations, batch 8, 640 px crops, --robust augmentation, from the textdet_robust checkpoint; loss weights synth 0.45 / Khmer PDF 0.20 / DocLayNet 0.35. Data: 15,000 synthetic train pages (docgen v2 + exam sheets + handwriting lines) / 750 val, DocLayNet 6,895 / 647, Khmer PDF 548 / 173. The kept checkpoint is iteration 24,000 (F1 during training: synthetic 0.896, DocLayNet 0.880, Khmer PDF 0.720). Final evaluation on 100 held-out pages per set: synthetic 0.923, Khmer PDF 0.877, DocLayNet 0.877.

Text recogniser (CRNN-CTC, arch "M": conv 48-96-192-256, proj 320, BiLSTM 2x256, 4.76 M params, line height 48)

Trainer: training/rec/train.py (the Khm-Dataset-Creation trainer + packed line sets), --aug strong (GPU warp, slant, low resolution, polarity), greedy CTC decoding. Vocabulary 195 symbols (Khmer, Latin, digits, punctuation), text normalised with normalize_khmer. Lineage (each step initialised from the previous best checkpoint):

  1. v1 (crnn_m_v1) β€” 6 epochs on mix_print_scene: synthetic print sections S01–S08 (200k lines sampled; news corpus rendered with 21 open-licence Khmer fonts + Khmer OS fonts, print/scan effects) + synthetic scene/signboard sets (dataset_v2 scene/heavy/medium/clean, nf_mix, hard, nf_hard, long). 739k lines/epoch.
  2. expA β€” 2 epochs adding real English lines from DocLayNet text layers (rec_doclaynet, 90,860 train lines).
  3. v2 (crnn_m_v2) β€” 6 epochs, lr 1e-3, on final_v2_hand: everything above + docgen printed lines (99,869) + synthetic handwriting lines from docgen exam sheets (69,081, Khmer handwriting fonts) + docgen form handwriting (11,905). 1.008 M lines/epoch. Val CER: synthetic print 0.22 %, English real 0.30 %, synthetic handwriting 4.8 %.
  4. v2.1 (crnn_m_v2_hw) β€” 3 epochs, lr 5e-4, on final_v2_hand_real: + real Khmer handwriting from Thareah/khmer-handwriting (2,311 train lines, x8 oversampled) and SoyVitou/khmer-handwritten-dataset-4.2k (3,549, x4). 1.041 M lines/epoch.
  5. v2.2 (crnn_m_v2_stamp) β€” 2 epochs with STAMP_AUG=0.12: training/rec/stamp_aug.py draws grey ring arcs and stamp strokes over 12 % of the crops so text under official red stamps is still read.
  6. v2.3 (crnn_m_v2_stamp2, default until 15 November 2026) β€” 4 epochs, lr 1.2e-4, same data and stamp augmentation, from v2.1. Val CER: synthetic print 0.216 %, English real 0.29 %, docgen 7.5 %, synthetic exam handwriting 4.5 %, real handwriting Thareah 21.5 % / SoyVitou 9.95 %, real signboard dev set 12.7 % (2,200 crops from lkhapple/KhmerOCR-Dataset, used for monitoring only).
  7. v2.4 (crnn_m_v2_stamp3) β€” 4 more epochs, lr 1e-4. Slightly better on every val set (print 0.213 %, real_dev 12.6 %); never made the default.
  8. v3 (crnn_m_v3_owner, default) β€” 4 epochs, lr 3e-4, from v2.3, on the v2 mix plus 4,943 real handwritten Khmer exam lines labelled by the owner (x8 oversampled), stamp augmentation 12 %. Held-out exam lines (434, split by page): CER 20.7 % β†’ 12.8 % (int8 13.0 %). Real English lines 0.88 % β†’ 0.84 %. Printed Khmer unchanged (0.225 %). Val: Thareah 17.8 %, SoyVitou 8.3 %.

int8 variants are dynamic-quantised exports of the same checkpoints (training/rec/export.py).

Font classifier (font/font_cnn_v2.onnx, FontNet, 483,034 params)

Trained entirely on synthetic line crops rendered on the fly (training/font/gen.py: Khmer news corpus + English sentences, PIL + HarfBuzz shaping, 29 font families: all Khmer OS faces, Noto Sans/Serif Khmer, Hanuman, Kantumruy Pro, Nokora, Odor Mean Chey, Chenla, Preahvihear, Suwannaphum, the Khmer display fonts (Koulen, Dangrek, Bayon, Angkor, Taprom) and Latin serif / sans; synthetic bold by dilation and italic by shear; neighbour-line intrusion, blur, noise, JPEG, paper tint). v1: 40 epochs x 400 steps x batch 256. v2: 24 epochs from v1 adding the em-size regression head. Val (8,000 held-out crops, kept epoch 20): family 92.3 %, weight 97.8 %, slant 99.9 %, size error median 1.8 %, 97.7 % of sizes within 10 %.

Structure model (structure/struct_v1.onnx, StructureNet, 983,412 params)

4-layer Transformer (d 160) over per-line geometric + text features, with a pointer head for reading order. Trained 30 epochs, batch 16, on docgen v3 pages with struct labels (9,786 train / 400 val synthetic pages). Val: role accuracy 0.988, paragraph-start F1 0.971, successor accuracy 0.964, Kendall tau 0.943.

Structure v3 (structure/struct_v3_pre.onnx, structure/struct_v3_tab.onnx, ~2.0 M params, preview)

6-layer Transformer (d 192) over the same per-line features as v1, plus heads for page kind (document / sheet / mixed), in-table lines and same-row / same-column / same-cell line pairs. struct_v3_pre was trained on docgen pages + phone-pipeline output of synthetic pages (photo-style val: role 0.95, successor 0.92, Kendall 0.94); its table heads are untrained. struct_v3_tab continues from it on docgen v5 table/sheet pages (6,846 train pages + 846 pipeline pages, 17 epochs). Val: role 0.997, page kind 1.00, in-table F1 1.00, same-row F1 0.84, same-column F1 0.98, same-cell F1 0.69; photo-style val: role 0.96, Kendall 0.94. Not the app default yet.

Table structure (table/tsr_yolo11n_mix.onnx, YOLO11n, 800 px table crops)

Classes: row, column, column_header, spanning_cell, projected_row_header. tsr_yolo11n_real_pre is a warm-up on PubTables-1M crops; tsr_yolo11n_mix fine-tunes it on PubTables-1M + FinTabNet + TabRecSet phone photos (incl. homography-rectified copies) + synthetic Khmer/English sheets (docgen v5), 23 epochs. Best val mAP50 0.836, mAP50-95 0.574.

Datasets

data type used by licence
Khmer news corpus (5,601 articles, 257k lines; scraped by the owner for research) rendered with open Khmer fonts synthetic rec, font text: research use; fonts OFL / LGPL
docgen v2 / v3 / v4 / exam synthetic pages (Project Gutenberg English, Faker identities, procedural logos/stamps/figures) synthetic layout, textdet, rec, structure generated
DocLayNet v2 real layout, textdet, rec (English lines) CDLA-Permissive 1.0
D4LA (form/invoice/letter/memo) real layout Apache-2.0 (mirror), page content third-party
CommonForms (checkbox boxes) real layout Apache-2.0
Real Khmer PDF pages (government/NGO PDFs crawl, heuristic labels) real layout, textdet research use
SignverOD signatures, mapo80 stamps real layout Apache-2.0 / CC-BY-4.0
Thareah/khmer-handwriting, SoyVitou/khmer-handwritten-dataset-4.2k real rec MIT
docgen v5 tables / sheets (synthetic Khmer + English tables, invoices, spreadsheets) synthetic structure v3, table structure generated
PubTables-1M real table structure CDLA-Permissive 2.0
FinTabNet real table structure CDLA-Permissive 1.0
TabRecSet (phone photos of tables) real table structure CC BY 4.0 (figshare) / CC BY-SA 4.0 (README)
Owner's handwritten exam lines (4,943 train / 396 val / 434 test line crops) real rec v3 private, not published
cTDaR, ICDAR 2013 table competition real evaluation only –
FUNSD, KhmerEduDoc real evaluation only (non-commercial) NC

Base weights: Ultralytics YOLO11 (AGPL-3.0 β€” the layout models inherit it), PaddleOCR PP-OCRv5 mobile detector (Apache-2.0). The owner's exam photos are private and are not published; from v3 the recogniser is fine-tuned on text-line crops cut from them, and no other model saw them.

Example images on this page: public statements of the Ministry of Foreign Affairs and International Cooperation of Cambodia, a public notice of the Ministry of Education, Youth and Sport, a published royal decree, and one table from the ICDAR 2013 table competition.

Licence

The repo mixes licences, so the Hub tag is license: other. Per stage:

Stage Files Licence
Layout layout/*.onnx, layout/layout_v1_12cls.pt AGPL-3.0 β€” fine-tuned from Ultralytics YOLO11 weights and inherits that licence
Text detection textdet/db_v1.onnx, textdet/db_v2.onnx, textdet/db_ppocrv5_orig.onnx Apache-2.0 β€” derived from (or identical to, for db_ppocrv5_orig) the PaddleOCR PP-OCRv5 mobile detector
Recognition rec/* Apache-2.0 β€” Copyright 2026 Thareah. Trained from scratch by the project
Font font/* Apache-2.0 β€” Copyright 2026 Thareah. Trained from scratch on synthetic data
Structure structure/*.onnx Apache-2.0 β€” Copyright 2026 Thareah. Trained from scratch on synthetic data
Table structure table/*.onnx AGPL-3.0 β€” fine-tuned from Ultralytics YOLO11 weights; training data incl. TabRecSet (CC BY / BY-SA 4.0, attribution required)

The licence texts are in the repo: every model folder has its own LICENSE file (rec/, font/, structure/ and textdet/: Apache License 2.0; layout/ and table/: GNU AGPL v3). LICENSE.md gives the overview and NOTICE the copyright and attribution lines.

What this means in practice:

  • Recogniser, font, structure and text-line models (Apache-2.0): free to use, change and ship, also in commercial products. Keep the LICENSE and NOTICE files with any copy you pass on, and say if you changed the files.
  • Layout and table models (AGPL-3.0): free to use, but if you ship them in a product or run them as a network service, AGPL applies to that work, or you need a commercial licence from Ultralytics. A fully permissive pipeline needs these two models replaced.

The licences cover the model weights. Training data licences are listed in the Datasets table above. FUNSD and KhmerEduDoc were used for evaluation only (non-commercial); no model weights were trained on them.

Downloads last month
58
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support

Model tree for Thareah/ThaOCR-models

Finetuned
(4)
this model

Datasets used to train Thareah/ThaOCR-models