DBNet Khmer Text Detector
A DBNet (Differentiable Binarization) text detection model for Khmer/English documents β MobileNetV3 backbone + FPN + DBHead. Detects bounding boxes around text lines; it does not perform OCR/recognition.
Trained from scratch on synthetic Cambodian-style documents (plain docs, ID cards, official letters). See dbnet-text-detector for the full training pipeline, data generators, and inference code.
2026-07-31 β the default weights changed.
khmer_dbnet_mobilenetv3.onnxnow serves v2, a fine-tune on realistic ID-card/official-letter documents. It detects noticeably more text on real photographed documents than v1 did. The previous weights remain available unchanged askhmer_dbnet_mobilenetv3_v1.onnxβ pin that file if you need the old behaviour.
Files
| File | Description |
|---|---|
khmer_dbnet_mobilenetv3.onnx |
Default. Currently identical to v2. Recommended for inference (torch-free, via onnxruntime) |
khmer_dbnet_mobilenetv3.pth |
PyTorch checkpoint of the default β for fine-tuning or DBNet.pytorch-based inference |
khmer_dbnet_mobilenetv3_v2.onnx / .pth |
v2 explicitly, pinned |
khmer_dbnet_mobilenetv3_v1.onnx / .pth |
v1 explicitly, pinned β the original release |
Usage
pip install dbnet-text-detector
from dbnet_detector import DBNetDetector
detector = DBNetDetector.from_pretrained() # current default (v2)
boxes, scores = detector.detect("your_image.jpg")
detector = DBNetDetector.from_pretrained("v1") # pin an older version
detector = DBNetDetector.from_pretrained(preset="display") # large display text
Weights are downloaded from this repo on first use and cached locally
(~/.cache/huggingface/hub).
Thresholds matter more than you'd expect
The library defaults to the document preset (box_thresh=0.3, short_size=1088), which is
tuned for dense scanned or photographed pages. The older box_thresh=0.6, short_size=736
values silently dropped whole text lines on real documents β on one sample page, 24 detected
lines versus 79 with the current defaults.
Large display text (posters, captions over photos) is the opposite case and needs
downscaling β use preset="display" (short_size=320). The model was trained on small
text lines inside 640px crops, so very large glyphs fall outside its training scale.
Versions & metrics
| Version | Training | Val F1 |
|---|---|---|
| v1 | from scratch on plain synthetic docs | 0.987 (v1 val set) |
| v2 (default) | v1 fine-tuned on synthetic ID cards / official letters | 0.933 (v2 val set) |
β οΈ These two numbers are not comparable and do not rank the models. Each is measured on its own in-distribution synthetic validation set, so each says "this model learned its own data" β not that v1 is better. On real photographed documents v2 detects substantially more text, which is what the fine-tune was for. Both figures are synthetic and in-distribution; neither is evidence of generalization to arbitrary real-world photographs. Validate on your own images.
License
MIT