YOLO - Khmer Text & Math Line Detection (v4.0)
State-of-the-art YOLO models specialized in detecting Khmer text lines and complex mathematical & physics formulas (fractions, square roots, integrals, vectors, limits, matrices, systems of equations) across Cambodian national secondary & high school textbooks (Grades 5 to 12, Mathematics & Physics).
Key Capabilities
- Single-Class Unified Line Detection (
text_line): Detects entire horizontal reading lines containing mixed Khmer Unicode text and LaTeX mathematical expressions. - High Resolution Document Understanding: Optimized for standard high-resolution textbook pages (
imgsz=1280). - Cross-Platform Deployments: Available in both native PyTorch (
.pt) and optimized ONNX (.onnx) formats for Server, Desktop, Web (WebAssembly/WebGPU), and Mobile applications. - Interactive Live Web Studio: Test all model checkpoints in real-time with customizable Confidence, Temper (IoU NMS), in-browser ONNX inference, and full-page viewing at khmer-math-detector Space.
Model Versions & Download Links
All weights are available for direct download from this repository:
| Model Checkpoint | Version | Formats | Primary Focus / Metrics | Direct Download Link |
|---|---|---|---|---|
best_khmer_Dectecv2_30e.pt 👑 | v4.0 (Default) | .pt (~6.2 MB) | Dectecv2 30 Epochs91.22% mAP@50, 90.99% Precision, 86.58% Recall | ⬇️ Download .pt |
best_khmer_line_detect_43pct.pt ⭐ | v3.1 | .pt (~5.9 MB).onnx (~11.7 MB) | Champion Line DetectorStrict line boundaries, ideal for OCR text cropping. | ⬇️ Download .pt⬇️ Download .onnx |
best_yolo_khmer_math_physics_v3.pt 🚀 | v3.0 | .pt (~5.5 MB).onnx (~10.1 MB) | Unified Math & Physics (54.4K images)74.93% mAP@50, 76.66% Recall, Box Loss: 0.935 | ⬇️ Download .pt⬇️ Download .onnx |
best_yolo_khmer_math_v2.pt ⚡ | v2.0 | .pt (~6.2 MB).onnx (~11.7 MB) | Math G7–G12 Full Textbooks83.83% mAP@50, 1,562 pages, 24,040 bboxes | ⬇️ Download .pt⬇️ Download .onnx |
best_yolo_khmer_math.pt 📐 | v1.0 | .pt (~6.8 MB) | Oriented Bounding Box (OBB)2 classes: khmer script and expression | ⬇️ Download .pt |
best.pt 🔥 | Latest | .pt (~5.5 MB) | Latest merged training run checkpoint | ⬇️ Download .pt |
Benchmark & Performance Comparison
| Metric | v1.0 (Baseline) | v2.0 (Math G7-G12) | v3.0 (Math & Physics 54.4K) | v3.1 (Champion Line Detector) | v4.0 (Dectecv2) |
|---|---|---|---|---|---|
| Scope | Basic Math crops | Math G7–G12 | Full MoEYS Math + Physics | Refined High-Precision Lines | Optimal Line Detection (30 Epochs) |
| Total Images | ~2,500 | 1,562 pages | 54,407 Images (46,245 Train | 8,162 Val) | Selected High-Density Textbooks | Same as v3.0 |
| Target Class | OBB (khmer/math) | Line Bounding Box | Line Bounding Box | text_line (Single Class) | text_line (Single Class) |
| mAP@50 | 43.31% | 83.83% | 74.93% (~75% on 54.4K items) | High Precision Strict BBoxes | 91.22% |
| mAP@50-95 | 29.62% | 64.85% | 55.25% | Optimal OCR Crop Aspect | 70.11% |
| Recall | 50.36% | 79.26% | 76.66% | 78.40% | 86.58% |
| Precision | - | - | - | - | 90.99% |
🛠️ Quickstart Usage
Option 1: Using PyTorch & Ultralytics (Recommended for Desktop/Server)
from ultralytics import YOLO
from huggingface_hub import hf_hub_download
# 1. Download the model from Hugging Face Hub
model_path = hf_hub_download(
repo_id="krotreaksmey/Yolo_Detect_khmer_math",
filename="best_khmer_Dectecv2_30e.pt" # Default v4.0 model
)
# 2. Load model
model = YOLO(model_path)
# 3. Run prediction on a textbook page
# Tip: Use imgsz=1280 for full A4 pages to preserve small subscripts and fractions!
results = model.predict(
source="path/to/textbook_page.png",
conf=0.25,
iou=0.45,
imgsz=1280
)
# 4. Extract bounding boxes
for r in results:
boxes = r.boxes.xyxy.cpu().numpy() # [x1, y1, x2, y2]
confs = r.boxes.conf.cpu().numpy()
for box, score in zip(boxes, confs):
x1, y1, x2, y2 = box.astype(int)
print(f"Line detected at [{x1}, {y1}, {x2}, {y2}] with confidence: {score:.2f}")
Option 2: Using ONNX Runtime (Cross-Platform / C++ / Python)
import onnxruntime as ort
import numpy as np
from PIL import Image
# Load ONNX model
session = ort.InferenceSession("best_khmer_line_detect_43pct.onnx")
# Load and preprocess image with 640x640 letterbox
im = Image.open("textbook_page.png").convert("RGB")
w, h = im.size
scale = min(640 / w, 640 / h)
nw, nh = int(w * scale), int(h * scale)
im_resized = im.resize((nw, nh), Image.Resampling.BILINEAR)
# Create 640x640 letterbox padded canvas
padded = Image.new("RGB", (640, 640), (114, 114, 114))
pad_x = (640 - nw) // 2
pad_y = (640 - nh) // 2
padded.paste(im_resized, (pad_x, pad_y))
# Normalize to float32 CHW [1, 3, 640, 640]
input_arr = np.array(padded, dtype=np.float32) / 255.0
input_arr = np.transpose(input_arr, (2, 0, 1))[np.newaxis, ...]
# Run inference
outputs = session.run(["output0"], {"images": input_arr})
predictions = outputs[0] # shape: (1, 5, 8400) -> [cx, cy, w, h, conf]
📚 Training Dataset Distribution (54,407 Samples)
The model training corpus covers the complete Ministry of Education, Youth and Sport (MoEYS) STEM curriculum:
- Mathematics Grade 5: 3,305 images
- Mathematics Grade 6: 3,277 images
- Mathematics Grade 7: 5,276 images
- Mathematics Grade 8: 548 images
- Mathematics Grade 9: 6,869 images
- Mathematics Grade 11 (Advance): 6,669 images
- Mathematics Grade 12 (Basic): 3,745 images
- Mathematics Grade 12 (Advance): 4,475 images
- Physics Grade 11: 7,181 images
- Physics Grade 12: 13,062 images
- Total Unified Images: 54,407 images (Train: 46,245 | Val: 8,162)
Training Visualizations

Related Resources
- Interactive Test Studio:
krotreaksmey/khmer-math-detector - PARSeq OCR Recognition Dataset:
krotreaksmey/khmer-math-textbook - Synthetic Math Formula Dataset:
krotreaksmey/synthetic_khmer_math - Google Colab Test Notebook:
Colab_Test_Model.ipynb
Citation
If you use this model or dataset in your research or project, please cite:
@misc{yolo_khmer_math_v3,
title={YOLO Khmer Text & Math Line Detection Model},
author={krotreaksmey},
year={2026},
publisher={Hugging Face},
url={https://huggingface.co/krotreaksmey/Yolo_Detect_khmer_math}
}