Linda OCR (line recognizer)

Small CRNN + CTC text-line recognizer exported to ONNX (about 4.4 MB). Reads printed text in Cyrillic, Latin and Polish letters. Used by the desktop search app Linda Probe as the optional "own model" OCR engine; works with any ONNX Runtime.

Files

  • model.onnx - input [N, 1, 48, W] float32 (grayscale 0..1), output [T, N, C+1] CTC logits, T = (W + 3) // 4.
  • charset.txt - one character per line; class 0 is the CTC blank, class k is line k of the charset (1-based).

Usage

import math, numpy as np, onnxruntime as ort
from PIL import Image

chars = open("charset.txt", encoding="utf-8").read().split("\n")  # see note below
sess = ort.InferenceSession("model.onnx", providers=["CPUExecutionProvider"])

def read_line(path):
    im = Image.open(path).convert("RGB")
    w = max(24, min(1024, math.ceil(im.width * 48 / im.height)))
    bucket = max(64, ((w + 63) // 64) * 64)           # pad width to a multiple of 64
    canvas = Image.new("RGB", (bucket, 48), "white")
    canvas.paste(im.resize((w, 48), Image.Resampling.BILINEAR), (0, 0))
    x = np.asarray(canvas.convert("L"), np.float32)[None, None] / 255.0
    logits = sess.run(None, {sess.get_inputs()[0].name: x})[0]   # [T, 1, C+1]
    ids, prev, out = logits[: (w + 3) // 4, 0].argmax(-1), 0, []
    for k in ids:
        if k and k != prev:
            out.append(chars[int(k) - 1])
        prev = k
    return "".join(out)

Note: read charset.txt exactly as the app does (localdocs_ocr.py, own-charset loader) - keep a space character line if the file has one; do not strip lines.

Limits

One text line per image, printed text. Not handwriting. Very long lines are cut to 1024 px width.

Evaluation

Character error rate on our own held-out test set of 5000 generated/real lines (231,890 characters): 0.0358 (exact-line accuracy 0.80). This is an in-house set, not a public benchmark; real scans can be worse.

Updates

Linda Probe checks the ETag of model.onnx and offers an update when it changes.

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