Folio Orient Bengali

A 432 kB ONNX model estimates the clockwise turn needed to read a scanned Bengali printed page. It runs locally on CPU or in a browser. If the text patches give weak evidence, the tool leaves the page for review. The Python tool can also ask Tesseract for a second opinion and transcribe the result.

বাংলা ছাপা বইয়ের স্ক্যান সোজা করতে ছবিটি খুলুন। মডেল কত ডিগ্রি ঘোরাতে হবে তা জানায়। সিদ্ধান্ত অনিশ্চিত হলে ছবি যেমন আছে তেমনই থাকে। ব্রাউজারে নিজে ঘুরিয়ে সংশোধিত ছবি PNG হিসেবে সংরক্ষণ করতে পারবেন।

On 32 held-out British Library pages, the Python model got 127 of 128 quarter-turns right before applying its confidence cutoff. It accepted 95 views at the cutoff and got all 95 right. Tesseract OSD accepted 107 and got all 107 right. Median processing time per page on one CPU core was 136 ms with Folio and 476 ms with a reused Tesseract instance. These measurements cover orientation of already decoded images. The four views of each page share the same content. Evaluation, predictions and timing

On a separate Digital Library of India test, the specialist accepted 181 of 188 Bengali or mixed-script views, with one wrong turn. It accepted a sideways two-line title page at 0.7879 agreement. Inspect sparse titles even when the model accepts them. OSD accepted 155 on that test and got all 155 right. Independent collection results and failure example

Rotate a page locally

From a shell with the Hugging Face CLI installed, download the runtime and a sideways public-domain sample. Python 3.10+ is recommended.

The source loader reads config.json to select the ONNX weights. The configuration also records their SHA-256 digest and the graph’s input and output shapes.

hf download foliokestrel/folio-orient-bengali --local-dir folio-bn \
  --include config.json \
  --include model.onnx \
  --include requirements.txt \
  --include '*.py' \
  --include examples/sideways.png
cd folio-bn
python -m pip install -r requirements.txt
python orient_bengali.py examples/sideways.png --output upright.png

The sample takes a 270° clockwise turn. The JSON output contains the proposed turn, the applied turn, the method, the patch agreement and whether the page needs review. An accepted 0° means that the page already reads upright. On a referral the applied turn is also 0°, with needs_review set to true. The 0.70 cutoff applies to mean patch probabilities. It has no calibrated probability interpretation.

For a batch, load the model once and pass each Pillow image to the same instance.

from PIL import Image
from folio_orient import PageOrienter, transpose_cw, visible_page
from orient_bengali import assess

orienter = PageOrienter()
with Image.open("examples/sideways.png") as image:
    decision = assess(image, orienter)
    upright = transpose_cw(visible_page(image), decision["applied_cw"])
    print(decision["needs_review"], upright.size)

Review a Bengali book PDF

The PDF reviewer proposes a turn for each physical page and writes an editable decision sheet. Try the five-page book extract with --strict to compare the direction estimates for a page and its upside-down view. PDF guide and worked review

A separate tool ranks likely sideways tables and maps in long scans. The eight-page example has three sideways tables among its first four suggestions. Open the linked page to decide whether it needs turning. Table finder and example

Use the browser

Download the local reader, then open http://127.0.0.1:8000/browser/. The page opens with a real scan. Choose a local image, inspect the result, adjust the turn if needed and save a lossless PNG. Its WebAssembly runtime, fonts and model load from the local server. The reader processes the images on the device.

hf download foliokestrel/folio-orient-bengali --local-dir folio-browser \
  --include config.json \
  --include 'browser/*' \
  --include 'examples/*' \
  --include model.onnx
python -m http.server 8000 --bind 127.0.0.1 --directory folio-browser

On the same 128 held-out views, Chromium accepted 102 at the 0.70 cutoff and got all 102 right. Browser canvas resampling can change the score near the cutoff. The browser offers manual review and rotation. Browser predictions · Runtime checks

Use Tesseract on referrals

The optional fallback asks Tesseract OSD for a turn only when the small model refers a page. If OSD returns confidence below 15 or gives no direction, the tool leaves the displayed page for review. Add --ocr to transcribe the applied orientation using Bengali trained data.

python -m pip install tesserocr==2.9.2
mkdir -p tessdata
rev=87416418657359cb625c412a48b6e1d6d41c29bd
curl -fL "https://raw.githubusercontent.com/tesseract-ocr/tessdata_fast/$rev/osd.traineddata" -o tessdata/osd.traineddata
curl -fL "https://raw.githubusercontent.com/tesseract-ocr/tessdata_fast/$rev/ben.traineddata" -o tessdata/ben.traineddata
python orient_bengali.py examples/sideways.png --osd-fallback --ocr --tessdata tessdata --dpi 400

This policy consulted OSD on 33 of 128 held-out views and accepted 109 turns with zero observed mistakes. With the same Tesseract Bengali recognizer, character error rate on 17 ordered held-out transcripts was 56.39% with the input as displayed, 31.86% after the specialist alone and 28.81% with either the fallback or OSD alone. We designed the fallback after seeing both panels. Its results are retrospective. Fallback results

Training and scope

Training used computer-rendered Bengali words, short phrases, numerals and some English text in 13 font faces. The 64 archival test pages contributed no training pixels or transcriptions. Those two panels come from the British Library. A third evaluation used 48 Digital Library of India pages outside that collection. Use the measured settings for quarter-turns of printed text. Handwriting, other scripts, mirrored images and small-angle deskew require separate evidence. The held-out example C020 illustrates a failure. The page needed a 180° turn, the model proposed 0° and its 0.3811 agreement sent the page to review. Training recipe and weights · Review example and source

The model weights, code and authored training text use Apache 2.0. The British Library marks the REID2019 images and transcriptions as public domain. Tom Derrick and the British Library published the collection with transcription contributions from Moumita Halder and collaboration from the PRImA Research Lab. The new orientation judgments and benchmark metadata are CC0. Font files and the browser runtime have their own notices. Software license · British Library source · CC0 dedication · Component credits

Downloads last month
45
Safetensors
Model size
108k params
Tensor type
F32
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for foliokestrel/folio-orient-bengali

Quantized
(2)
this model