Pashto OCR - CRNN + CTC (printed + handwritten)

Line-level Pashto OCR (CRNN: VGG-style CNN + 2-layer BiLSTM + CTC, ~12M params).

  • crnn.pt - stage-1 weights: printed / on-screen text (trained on zirak-ai/PashtoOCR). Printed validation CER = 0.0368 / WER = 0.1210
  • crnn_pashtoOCR.pt - stage-2 weights: fine-tuned on KPTI (17k real hand-scribed Pashto text lines). Reads katib-style handwritten manuscripts as well as printed text. KPTI test CER = 0.0563 / WER = 0.2299.
  • charset.json - character vocabulary + preprocessing config

Preprocessing contract

Grayscale, dark-text-on-light (auto-invert dark themes), resized to height 48 (aspect preserved), normalized to [-1, 1], then horizontally flipped (RTL script -> left-to-right CTC frames). Decode with greedy CTC (collapse repeats, drop blank id 0).

Usage

import json, torch
from huggingface_hub import hf_hub_download

weights = hf_hub_download("mhalimi3008/pashtoOCR", "crnn_pashtoOCR.pt")   # or crnn.pt
cfg = json.loads(open(hf_hub_download("mhalimi3008/pashtoOCR", "charset.json")).read())
model = CRNN(len(cfg["charset"]) + 1).eval()      # CRNN class from the training notebook
model.load_state_dict(torch.load(weights, map_location="cpu"))

The training notebook (sections 5-6 and 10) contains the full inference code, including projection-profile line segmentation and PDF support.

If you use the handwriting weights in research, cite: Ahmad et al., "KPTI: Katib's Pashto Text Imagebase and Deep Learning Benchmark", ICFHR 2016.

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support