tinylens/tiny-manga-ocr-small

A tiny Japanese manga OCR model. Give it a crop of one speech bubble or text block (vertical or horizontal) and it returns the text. 7.4M parameters, 11 MB as int8 ONNX, small enough to run in a web browser. It is a lighter alternative to kha-white/manga-ocr-base (111M parameters, 424 MB).

Use

The model is split into an image encoder and a text decoder that is called once per output character (greedy decoding, up to 62 characters).

import json, numpy as np, onnxruntime as ort
from huggingface_hub import snapshot_download
from PIL import Image

d = snapshot_download("tinylens/tiny-manga-ocr-small")
enc = ort.InferenceSession(f"{d}/onnx/encoder_quantized.onnx")
dec = ort.InferenceSession(f"{d}/onnx/decoder_quantized.onnx")
vocab = json.load(open(f"{d}/onnx/vocab.json"))

def read(path):
    # grayscale, stretch to 224x224 (no aspect ratio kept), scale to [-1, 1]
    g = np.asarray(Image.open(path).convert("L").resize((224, 224), Image.BICUBIC), np.float32) / 255
    x = np.repeat(((g - 0.5) / 0.5)[None, None], 3, axis=1)
    memory = enc.run(None, {"pixel_values": x})[0]
    ids = [2]  # BOS
    for _ in range(63):
        nxt = int(dec.run(None, {"memory": memory, "input_ids": np.array([ids], np.int64)})[0][0].argmax())
        if nxt == 3:  # EOS
            break
        ids.append(nxt)
    return "".join(vocab[i] for i in ids[1:] if i >= 15)

print(read("bubble.png"))

Files: onnx/encoder.onnx + onnx/decoder.onnx (fp32, 29 MB), onnx/encoder_quantized.onnx + onnx/decoder_quantized.onnx (int8 weights, 11 MB), onnx/vocab.json, onnx/preprocess.json. PyTorch: model.safetensors with model.py (TinyOCR; the output layer shares weights with the token embedding, so load with strict=False and the tie restores it).

The model reads one text block at a time. It does not find text on a page; use a text detector first (for example ogkalu/comic-text-and-bubble-detector).

Evaluation

Manga109-s, the text boxes of 10 titles that were never used for training or model selection (13,722 crops, each box with a 10 px margin): BEMADER_P, Donburakokko, JijiBabaFight, LancelotFullThrottle, MAD_STONE, RinToSiteSippuNoNaka, RisingGirl, SeisinkiVulnus, SonokiDeABC, TensiNoHaneToAkumaNoShippo. The titles were fixed by a seeded rule before any training. All models were run by us on the same crops.

CER is the character error rate after NFKC normalization and removing whitespace, with writing-convention variants folded: runs of dots (・・・, ......, …) to ..., wave dashes to ~, quote marks to ", and dash variants to ー. Most of manga-ocr-base's raw errors on this set were such variants rather than misreadings. The strict CER does not fold them. Exact match is the share of crops read entirely correctly (folded).

Model Params Size (MB) License CER % Exact match % Strict CER % CPU, 4 threads, per crop
tinylens/tiny-manga-ocr-small (this model) 7.4M 11 (int8) / 29 (fp32) apache-2.0 3.66 84.7 6.60 26 ms (int8 ONNX)
tinylens/tiny-manga-ocr-base 24.3M 33 (int8) / 94 (fp32) apache-2.0 3.05 85.9 6.09 67 ms (int8 ONNX)
kha-white/manga-ocr-base 111M 424 apache-2.0 3.61 84.5 8.04 197 ms (PyTorch)

int8 ONNX of this model on the same crops: CER 3.67%, exact match 84.7%.

Where this model is behind manga-ocr-base: CER (3.66% vs 3.61%); CER on texts of 1-5 characters (6.01% vs 5.26%); CER on texts of 6-15 characters (2.95% vs 2.91%); CER on texts of 31+ characters (12.21% vs 11.12%).

Caveat in manga-ocr-base's favour. manga-ocr-base was trained on a random 90% of all Manga109-s text boxes across every title, so it saw roughly 90% of these test crops during training. This model never saw the test titles.

CER by text length (characters):

Length This model manga-ocr-base
1-5 6.01 5.26
6-15 2.95 2.91
16-30 2.20 2.45
31+ 12.21 11.12

Training

  • Architecture: ConvNeXt-atto (timm convnext_atto.d2_in1k, Apache-2.0) + 4-layer Transformer decoder (width 256), input 224x224 grayscale, character vocabulary of 6,144 from manga-ocr-base's tokenizer.
  • Stage 1: synthetic text only. Japanese snippets from CC-100 rendered with 25 SIL Open Font License fonts from google/fonts, vertical and horizontal, 1-3 lines, with screentone, gradient and speed-line backgrounds, outlines, blur, noise and downscaling. 90,000 steps of 64 images.
  • Stage 2: half of each batch from the 72 Manga109-s training titles (103,377 text boxes), half synthetic, 40,000 steps of 64, AdamW lr 0.0003, cosine schedule. The checkpoint was selected on 5 further held-out titles.
  • Hardware: one RTX 5070 Ti.
  • Code for data, training, evaluation and export: https://github.com/DenDen047/agent-earning/tree/main/manga_ocr

Limitations

  • One text block per crop. Long blocks are squeezed into a 224x224 square, and output stops at 62 characters.
  • Manga109 titles are mostly from the 1970s to 2010s. Expect lower accuracy on unusual lettering, hand-written sound effects, very small furigana, and styles far from the training data.
  • Furigana are not transcribed separately; the model is trained to output the main text as annotated in Manga109-s.
  • The vocabulary has no characters outside manga-ocr-base's 6,144; rare kanji may come out wrong.

License and attribution

Model weights and code: Apache-2.0.

This model was trained using the Manga109-s dataset. Manga109-s is provided for use under its own terms; no manga images are included in this repository or the demo. If you use this model in academic work, please also cite:

  • Baek, Miyai, Onohara, Ikuta, Aizawa. "Manga109-v2026: Revisiting Manga109 Annotations for Modern Manga Understanding." ICML Workshop, 2026.
  • Aizawa et al. "Building a Manga Dataset 'Manga109' with Annotations for Multimedia Applications." IEEE MultiMedia 27(2), 2020.
  • Matsui et al. "Sketch-based Manga Retrieval using Manga109 Dataset." Multimedia Tools and Applications 76(20), 2017.

Synthetic text: sentences from CC-100 (Conneau et al., ACL 2020; Wenzek et al., LREC 2020), used only to render training images. Fonts: SIL Open Font License 1.1, not redistributed. Vocabulary: from kha-white/manga-ocr-base (Apache-2.0), which derives from tohoku-nlp/bert-base-japanese-char-v2. Backbone weights: timm, Apache-2.0.

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

Model tree for tinylens/tiny-manga-ocr-small

Quantized
(1)
this model

Dataset used to train tinylens/tiny-manga-ocr-small

Space using tinylens/tiny-manga-ocr-small 1