Reza2kn's picture
ONNX Runtime engine (default, statically linked), parallel detector branches, INT8 reader, convex-hull fix; tract kept as a feature
e18be61 verified
|
Raw History Blame Contribute Delete
3.36 kB
metadata
language:
  - fa
license: cc-by-nc-4.0
base_model: Reza2kn/Bina-0.4-Microscopy
base_model_relation: quantized
pipeline_tag: image-to-text
tags:
  - bina
  - ocr
  - persian
  - farsi
  - rust
  - onnxruntime
  - tract
  - onnx
  - on-device

Bina 0.4 Microscopy 路 Rust

Bina 0.4 Microscopy (9.55M parameters, Persian page OCR) as one native program. The whole page pipeline is ported to Rust (detection, router, reading order, CTC decoding, right-to-left text, duplicate clean-up). The networks run on ONNX Runtime, statically linked into the binary, or on tract for a pure-Rust build.

The two detector branches run in parallel threads, each with its own reader session, so the full two-detector mode costs little more than a single detector on a multi-core CPU.

Build Reader 193 crops CER dev50 CER s/page (dev50)
Python + ONNX Runtime, main repo FP32 19.09 14.46 0.55
Rust + ONNX Runtime (this repo, default) FP32 19.06 14.45 0.56
Rust + ONNX Runtime (this repo, default) INT8 (--reader reader.int8.onnx) 19.32 14.62 0.44
Rust + ONNX Runtime, --single INT8 20.63 15.09 0.29
Rust + tract (pure Rust) FP32 19.08 14.45 2.2

Full handwritten pages, 4 threads per branch on an x86 desktop CPU; no-space CER %, lower is better. --single (main detector only) is just as good on handwriting, prose, forms and screenshots, and weaker on tables.

Run the prebuilt binary (Linux x86-64)

hf download Reza2kn/Bina-0.4-Microscopy-Rust --local-dir bina-rs
cd bina-rs
chmod +x bin/bina-microscopy-linux-x86_64
./bin/bina-microscopy-linux-x86_64 --models models --out results examples/demo.png page.jpg
./bin/bina-microscopy-linux-x86_64 --models models --reader reader.int8.onnx page.jpg      # faster
./bin/bina-microscopy-linux-x86_64 --models models --reader reader.int8.onnx --single page.jpg   # fastest, no tables

One self-contained executable: ONNX Runtime is linked in, nothing else to install. Each image gives results/<name>.txt and results/<name>.json (lines with boxes and confidences), the same format as the Python version. Images: PNG, JPEG, WebP, TIFF; render PDF pages to images first.

Environment: BINA_THREADS=n sets threads per branch (default 4), BINA_SEQUENTIAL=1 runs the two branches one after the other.

Build

cargo build --release                                      # ONNX Runtime engine (downloads a prebuilt ONNX Runtime, linked statically)
cargo build --release --no-default-features --features tract   # pure Rust: no C++ at all, cross-compiles anywhere incl. WebAssembly

Rust 1.85+. Dependencies: ort (or tract-onnx + tract-linalg), image, serde_json, anyhow.

Files

File What
src/main.rs the pipeline, both engines and the CLI
models/reader.onnx, models/reader.int8.onnx CTC line reader, FP32 and INT8 convolutions
models/det_main.onnx, models/det_print.onnx the two line detectors
models/vocab.json, models/vocab_bidi.json vocabulary and bidi classes for right-to-left reordering
bin/bina-microscopy-linux-x86_64 prebuilt release binary (ONNX Runtime engine)

License

CC BY-NC 4.0, as the main model.