Image Classification
timm
ONNX
Safetensors
ocr
script-identification
page-classification
document-ai
multi-label
glam
knowledge-distillation
hf_jobs
Instructions to use davanstrien/page-script-id with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- timm
How to use davanstrien/page-script-id with timm:
import timm model = timm.create_model("hf-hub:davanstrien/page-script-id", pretrained=True) - Notebooks
- Google Colab
- Kaggle
Update repo links after rename to davanstrien/page-script-id
Browse files
README.md
CHANGED
|
@@ -59,7 +59,7 @@ A fast, compact image model that looks at a document page and predicts which wri
|
|
| 59 |
Built on **MobileNetV4-conv-small** (2.52M parameters, 10.1 MB as ONNX or `timm` weights), distilled from a 3-family teacher ensemble (`convnext_small`, `hgnetv2_b4`, `caformer_s36`) on [Hugging Face Jobs](https://huggingface.co/docs/hub/jobs). Takes a greyscale page squashed to `640 × 640` and runs in **33 ms** on 1 CPU thread, **11 ms** on 4 threads, or **1,773 pages/s** on an A10G (`bf16`, batch 64).
|
| 60 |
|
| 61 |
- **Try it live:** [Page Script ID Demo Space](https://huggingface.co/spaces/davanstrien/page-script-id-demo) (runs on free CPU — upload images or PDFs, toggle crop padding, tune thresholds live)
|
| 62 |
-
- **Higher-accuracy sibling:** [`davanstrien/page-script-id-
|
| 63 |
|
| 64 |
> **Check the thresholds on your own pages.** The default cut-offs (`0.55` for a script, `0.7038` for `unknown`) were chosen on held-out web-PDF validation pages (95% coverage). On government documents this refuses ~8% and on photographed documents ~28%. Run on a few hundred of your own pages and tune `unknown_threshold` and `script_threshold` in `config.json` before bulk routing.
|
| 65 |
|
|
@@ -92,9 +92,9 @@ import torch
|
|
| 92 |
from huggingface_hub import hf_hub_download
|
| 93 |
from PIL import Image
|
| 94 |
|
| 95 |
-
model_id = "hf-hub:davanstrien/page-script-id
|
| 96 |
model = timm.create_model(model_id, pretrained=True).eval()
|
| 97 |
-
cfg = json.loads(Path(hf_hub_download("davanstrien/page-script-id
|
| 98 |
size = cfg["input_size"]
|
| 99 |
mean = torch.tensor(model.pretrained_cfg["mean"]).view(3, 1, 1)
|
| 100 |
std = torch.tensor(model.pretrained_cfg["std"]).view(3, 1, 1)
|
|
@@ -124,7 +124,7 @@ for path, p in zip(sys.argv[1:], probs):
|
|
| 124 |
|
| 125 |
All test benchmarks are strictly held out from training (never trained on test documents, MDPBench, OmniDocBench, Sarvam Indic OCR Bench, or held-out unseen scripts Gurmukhi/Sinhala). Top-1 accuracy is unthresholded (before the `unknown` rule). "2 seeds" is the range over two distilled runs of this recipe (`s0` selected by `r2_val`; `s1` shown for spread).
|
| 126 |
|
| 127 |
-
| Benchmark | Label | n | **This model** | 2 seeds | Sibling `
|
| 128 |
|---|---|---:|---:|---:|---:|
|
| 129 |
| Web PDFs (`r2_test`), text layer | text layer | 2,056 | **94.0%** | 93.9–94.0% | 94.1% |
|
| 130 |
| Web PDFs (`r2_test`), doc label | doc language | 2,695 | **94.3%** | 93.5–94.3% | 94.4% |
|
|
|
|
| 59 |
Built on **MobileNetV4-conv-small** (2.52M parameters, 10.1 MB as ONNX or `timm` weights), distilled from a 3-family teacher ensemble (`convnext_small`, `hgnetv2_b4`, `caformer_s36`) on [Hugging Face Jobs](https://huggingface.co/docs/hub/jobs). Takes a greyscale page squashed to `640 × 640` and runs in **33 ms** on 1 CPU thread, **11 ms** on 4 threads, or **1,773 pages/s** on an A10G (`bf16`, batch 64).
|
| 60 |
|
| 61 |
- **Try it live:** [Page Script ID Demo Space](https://huggingface.co/spaces/davanstrien/page-script-id-demo) (runs on free CPU — upload images or PDFs, toggle crop padding, tune thresholds live)
|
| 62 |
+
- **Higher-accuracy sibling:** [`davanstrien/page-script-id-hgnet`](https://huggingface.co/davanstrien/page-script-id-hgnet) (HGNetV2-B0, 3.99M parameters, 16 MB, 79 ms 1t / 36 ms 4t, 88.0% MDPBench photographed)
|
| 63 |
|
| 64 |
> **Check the thresholds on your own pages.** The default cut-offs (`0.55` for a script, `0.7038` for `unknown`) were chosen on held-out web-PDF validation pages (95% coverage). On government documents this refuses ~8% and on photographed documents ~28%. Run on a few hundred of your own pages and tune `unknown_threshold` and `script_threshold` in `config.json` before bulk routing.
|
| 65 |
|
|
|
|
| 92 |
from huggingface_hub import hf_hub_download
|
| 93 |
from PIL import Image
|
| 94 |
|
| 95 |
+
model_id = "hf-hub:davanstrien/page-script-id"
|
| 96 |
model = timm.create_model(model_id, pretrained=True).eval()
|
| 97 |
+
cfg = json.loads(Path(hf_hub_download("davanstrien/page-script-id", "config.json")).read_text())["inference"]
|
| 98 |
size = cfg["input_size"]
|
| 99 |
mean = torch.tensor(model.pretrained_cfg["mean"]).view(3, 1, 1)
|
| 100 |
std = torch.tensor(model.pretrained_cfg["std"]).view(3, 1, 1)
|
|
|
|
| 124 |
|
| 125 |
All test benchmarks are strictly held out from training (never trained on test documents, MDPBench, OmniDocBench, Sarvam Indic OCR Bench, or held-out unseen scripts Gurmukhi/Sinhala). Top-1 accuracy is unthresholded (before the `unknown` rule). "2 seeds" is the range over two distilled runs of this recipe (`s0` selected by `r2_val`; `s1` shown for spread).
|
| 126 |
|
| 127 |
+
| Benchmark | Label | n | **This model** | 2 seeds | Sibling `page-script-id-hgnet` |
|
| 128 |
|---|---|---:|---:|---:|---:|
|
| 129 |
| Web PDFs (`r2_test`), text layer | text layer | 2,056 | **94.0%** | 93.9–94.0% | 94.1% |
|
| 130 |
| Web PDFs (`r2_test`), doc label | doc language | 2,695 | **94.3%** | 93.5–94.3% | 94.4% |
|