The higher-accuracy sibling to
davanstrien/page-script-id
(MobileNetV4-Small). It looks at a full document page (greyscale,
640 × 640
) and returns an independent calibrated probability for each of 21 writing scripts, or
unknown
, without running OCR.
Built on
hgnetv2_b0.ssld_stage2_ft_in1k
(3.99M parameters, 16.0 MB ONNX):
~79 ms
on 1 CPU thread /
~28–36 ms
on 4 threads (~10× faster than ConvNeXt-Tiny on CPU),
621 pages/s
on an A10G in
bf16
. Compared to the 2.52M MobileNetV4-Small variant, it adds
+3.2 pts on photographed documents (88.0%, 97.6% 1-script accuracy)
, higher accuracy on government scans (
90.9%
),
100%
on square-padded Kannada crops, and
91.3%
refusal on real held-out 2026 Sinhala PDFs.
Faster sibling:
davanstrien/page-script-id
(MobileNetV4-Small, 2.52M, 33 ms 1t / 11 ms 4t CPU, 1,773 pages/s A10G)
Check the thresholds on your own pages.
The default cut-offs (
0.55
for a script,
0.7314
for
unknown
) were chosen on held-out web-PDF validation pages (95% coverage). On government documents this refuses ~10% and on photographed documents ~29% (with 97.6% accuracy on answered single-script pages). Adjust
unknown_threshold
and
script_threshold
in
config.json
on a sample of your own collection.
21 scripts:
Arabic (
Arab
), Armenian (
Armn
), Bengali (
Beng
), Cyrillic (
Cyrl
), Devanagari (
Deva
), Ethiopic (
Ethi
), Georgian (
Geor
), Greek (
Grek
), Gujarati (
Gujr
), Han (
Hani
), Hangul (
Hang
), Hebrew (
Hebr
), Japanese (
Jpan
), Kannada (
Knda
), Khmer (
Khmr
), Latin (
Latn
), Malayalam (
Mlym
), Myanmar (
Mymr
), Tamil (
Taml
), Telugu (
Telu
), Thai (
Thai
).
Preprocessing: greyscale, bilinear squash to
640 × 640
, float32
0..255
. ImageNet normalisation, temperature (
1.10
), and sigmoid are baked inside
model.onnx
, which outputs the 21 calibrated probabilities directly.
Use with
timm
model.safetensors
holds the same weights for
timm
(
hgnetv2_b0
, 21 outputs in
label_names
order). Apply
sigmoid(logits / 1.10)
to its output logits.
import json
import sys
from pathlib import Path
import timm
import torch
from huggingface_hub import hf_hub_download
from PIL import Image
model_id = "hf-hub:davanstrien/page-script-id-hgnet"
model = timm.create_model(model_id, pretrained=True).eval()
cfg = json.loads(Path(hf_hub_download("davanstrien/page-script-id-hgnet", "config.json")).read_text())["inference"]
size = cfg["input_size"]
mean = torch.tensor(model.pretrained_cfg["mean"]).view(3, 1, 1)
std = torch.tensor(model.pretrained_cfg["std"]).view(3, 1, 1)
defload_page(path):
im = Image.open(path)
if im.format == "JPEG":
im.draft("L", (2 * size, 2 * size))
grey = im.convert("L").resize((size, size), Image.BILINEAR)
x = torch.frombuffer(bytearray(grey.tobytes()), dtype=torch.uint8).float().view(1, size, size) / 255return (x.expand(3, -1, -1) - mean) / std
with torch.inference_mode():
x = torch.stack([load_page(p) for p in sys.argv[1:]])
probs = torch.sigmoid(model(x) / cfg["temperature"])
for path, p inzip(sys.argv[1:], probs):
if p.max() < cfg["unknown_threshold"]:
print(path, ["unknown"])
else:
print(path, [cfg["scripts"][i] for i in p.argsort(descending=True) if p[i] >= cfg["script_threshold"]])
Evaluation
All test sets are strictly held out from training. 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 = 92.6%
;
s1
shown for spread).
*(Single-script spurious 2+ rate on
r2_test
:
2.2%
at
0.55
; mixed-script exact set on
r2_test
at
0.50
without gate:
47.0%
.)*
Unseen scripts:
Real 2026 Sinhala (
Sinh
) PDFs
(46 full pages from
CC-MAIN-2026-47
, never trained):
91.3%
refused as
unknown
(2 seeds: 82.6–91.3%).
Clean synthetic unseen (
Guru
,
Sinh
)
(NVIDIA v2 shard 00000, 160 pages):
58.8%
refused.
Exact 18-class leave-out
(
Geor
,
Khmr
,
Telu
removed from training, 855
r3
pages, undistilled
hgnetb0
, 2 seeds):
45.9–49.1%
pooled refused by
max(prob)
(
Geor
91–92%,
Khmr
27–40%,
Telu
14–27%; most false accepts on
Khmr
are
Latn
due to secondary Latin headings on Cambodian government PDFs, and
Telu
is confused with its visual twin
Knda
). Combining
max(prob)
with cosine similarity to pre-logit class centroids raises pooled refusal to
53.5–61.3%
(AUROC 0.903–0.906) while keeping known-script refusal under 8%. This model is
not
a reliable detector for unseen scripts.
Speed & Parity
Measured on a cloud
a10g-large
box (12 vCPU, 1× A10G), model forward only on random input (image decode adds ~15–30 ms on 1 CPU thread):
Setup
Speed
Notes
ONNX Runtime FP32, 1 CPU thread, batch 1
78.7–79.5 ms / page
15.99 MB
file
ONNX Runtime FP32, 4 CPU threads, batch 1
27.9–36.0 ms / page
PyTorch (
timm
), A10G,
bf16
, batch 64
621 pages / sec
ONNX ↔ PyTorch parity
(400
r2_val
pages):
max |prob diff| = 1.2e-6
,
100.0% top-1 agreement
. Post-training static INT8 quantization degraded top-1 agreement to 49.5% and was not shipped.
Limits
Unseen scripts & look-alikes:
not an unseen-script detector (Telugu held out with Kannada trained is often called Kannada; unseen scripts on pages with Latin headers often fire
Latn
).
Weakest known scripts (
r3_test
):
Telugu (
62.0%
) and Gujarati (
70.7–72.4%
).
Photographed Cyrillic (
ru
):
51.7–52.5%
top-1 under heavy photographic distortion (often confused with Latin or refused as unknown).
Crops:
raw squashed text-block crops are mostly refused (
35.3%
top-1); pad to a white square (
--pad
) to reach
86.0%
on real Indic crops (
100%
on Kannada).
Not a "no-text" detector:
pair with a dedicated no-text classifier (e.g.
small-models-for-glam/page-ocr-flags
) when blank filtering is critical.
Training & Attribution
Real PDFs:
born-digital & scanned pages from
FinePDFs
(
ODC-By
; we thank its authors), 3,794 fresh 2026 PDFs from
Common Crawl
(
CC-MAIN-2026-47
, page-level Unicode text-layer labels), plus library/archive scans (BHL, US government docs, IDL) labelled by vision-language model agreement. No raw page images are redistributed.
Teachers & Distillation:
3-family ensemble of
timm/convnext_small.fb_in22k_ft_in1k_384
,
timm/hgnetv2_b4.ssld_stage2_ft_in1k
, and
timm/caformer_s36.sail_in22k_ft_in1k_384
(all Apache-2.0) distilled into
timm/hgnetv2_b0.ssld_stage2_ft_in1k
(Apache-2.0) for 14 epochs with Asymmetric Loss + soft BCE KD (
alpha=0.50, T=1.5
), oblique/curl/hand/rotation/padded-crop/CutMix augmentation, EMA weights, and
OneCycleLR
.
Compute:
trained on
Hugging Face Jobs
(~82 min on
a10g-large
for the distilled student).
Runs of davanstrien page-script-id-hgnet on huggingface.co
88
Total runs
0
24-hour runs
44
3-day runs
58
7-day runs
58
30-day runs
More Information About page-script-id-hgnet huggingface.co Model
page-script-id-hgnet huggingface.co is an AI model on huggingface.co that provides page-script-id-hgnet's model effect (), which can be used instantly with this davanstrien page-script-id-hgnet model. huggingface.co supports a free trial of the page-script-id-hgnet model, and also provides paid use of the page-script-id-hgnet. Support call page-script-id-hgnet model through api, including Node.js, Python, http.
page-script-id-hgnet huggingface.co is an online trial and call api platform, which integrates page-script-id-hgnet's modeling effects, including api services, and provides a free online trial of page-script-id-hgnet, you can try page-script-id-hgnet online for free by clicking the link below.
davanstrien page-script-id-hgnet online free url in huggingface.co:
page-script-id-hgnet is an open source model from GitHub that offers a free installation service, and any user can find page-script-id-hgnet on GitHub to install. At the same time, huggingface.co provides the effect of page-script-id-hgnet install, users can directly use page-script-id-hgnet installed effect in huggingface.co for debugging and trial. It also supports api for free installation.
page-script-id-hgnet install url in huggingface.co: