| --- |
| license: mit |
| library_name: dbnet-text-detector |
| pipeline_tag: object-detection |
| tags: |
| - text-detection |
| - dbnet |
| - khmer |
| - ocr |
| - onnx |
| --- |
| |
| # DBNet Khmer Text Detector |
|
|
| A [DBNet](https://arxiv.org/abs/1911.08947) (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](https://github.com/netra-ai-lab/DBNet-Text-Detection) for |
| the full training pipeline, data generators, and inference code. |
|
|
| > **2026-07-31 β the default weights changed.** `khmer_dbnet_mobilenetv3.onnx` now 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 as `khmer_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 |
|
|
| ```bash |
| pip install dbnet-text-detector |
| ``` |
|
|
| ```python |
| 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 |
| **down**scaling β 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 |
|
|