talira

Transformer-based optical character recognition with pre-trained image and text Transformers

open sourceMITself-hostablefree

TrOCR is a family of text recognition models from Microsoft Research, introduced in the paper "TrOCR: Transformer-based Optical Character Recognition with Pre-trained Models" (AAAI 2023). Each is an encoder-decoder: an image Transformer initialised from BEiT reads the image in 16x16 patches and a text Transformer initialised from RoBERTa generates the text. Microsoft released small (62M parameters), base (334M) and large (558M) sizes, each fine-tuned for handwriting on the IAM dataset, for printed receipts on SROIE, or for scene text, plus the pre-trained stage-1 checkpoints for your own fine-tuning. The weights are on Hugging Face and run with Hugging Face Transformers; the original fairseq code is in Microsoft's unilm repository under the MIT licence.

Problems it solves

  • recognise handwritten text lines from scanned notes with an open model I run myself
  • transformer OCR model I can fine-tune on my own handwriting samples or historical documents
  • read printed receipt text line by line with an open-weights model
  • MIT-licensed handwriting recognition model that runs locally with Hugging Face Transformers
  • recognise the text in cropped line images that my own text detector already found
  • scene text recognition model for words photographed in natural images
  • pretrained OCR encoder-decoder checkpoint to start from instead of training from scratch

Features

  • handwritten variants fine-tuned on IAM (cased CER 4.22 small, 3.42 base, 2.89 large)
  • printed variants fine-tuned on SROIE receipts (F1 95.86 to 96.60)
  • scene text recognition (STR) variants
  • stage-1 pre-trained checkpoints for fine-tuning
  • small 62M, base 334M and large 558M parameter sizes
  • BEiT image encoder and RoBERTa text decoder
  • TrOCRProcessor and VisionEncoderDecoderModel in Hugging Face Transformers
  • original fairseq training and fine-tuning scripts

Limitations

  • Doesn't read whole pages: each model reads a single line of text from a cropped image, so a separate text detector must find the lines first12

Capabilities

Has official SDKsplan not known

Alternatives

The same job

These do what TrOCR does.

  1. PP-OCRv5 PaddleOCR's fifth-generation text detection and recognition models, server and mobile sizes
  2. PP-OCRv6 PaddleOCR's sixth-generation text detection and recognition models, from 1.5M to 34.5M parameters
  3. Tesseract Tesseract Open Source OCR Engine
  4. docTR Document Text Recognition: open source OCR powered by PyTorch
  5. EasyOCR Ready-to-use OCR with 80+ supported languages and all popular writing scripts
  6. Mistral OCR Mistral AI's document OCR model and API: PDFs and images to structured Markdown, priced per page

Compare TrOCR with the top 3