TrOCR: Transformer-Based Optical Character Recognition with Pre-trained Models

Minghao Li, Tengchao Lv, Jingye Chen, Lei Cui, Yijuan Lu, Dinei A. F. Florêncio, Cha Zhang, Zhoujun Li, Furu Wei

Introduction

Optical Character Recognition (OCR) has traditionally relied on multi-stage pipelines. Most modern systems utilize a "hybrid" approach where a Convolutional Neural Network (CNN) extracts visual features and a Recurrent Neural Network (RNN) or Transformer acts as the language decoder. However, these systems often struggle with three main hurdles: the necessity of training from scratch, the inherent inductive biases of CNNs that may not suit all text types, and the complexity of adding external language models or decoding steps like Connectionist Temporal Classification (CTC) to achieve high accuracy.

TrOCR (Transformer-based OCR) addresses these challenges by introducing a pure, end-to-end Transformer-based model that completely removes traditional CNN backbones. By leveraging large-scale pre-trained models from both computer vision and natural language processing, TrOCR achieves state-of-the-art performance on printed, handwritten, and scene text recognition without complex post-processing.

Methods and Architecture

TrOCR adopts a "vanilla" Transformer encoder-decoder architecture. The simplicity of the model is one of its primary strengths, as it treats OCR essentially as a translation task—translating image pixels into natural language tokens.

The TrOCR architecture utilizes a Vision Transformer encoder and a standard Transformer decoder to process image patches into text tokens.

The Encoder and Decoder

Instead of using a CNN to extract features, the TrOCR encoder resizes an input image (e.g., to 384x384) and splits it into a sequence of 16x16 patches. These patches are flattened and fed into a Vision Transformer (ViT-style) encoder. The decoder is a standard Transformer decoder that receives visual features from the encoder and generates text tokens (wordpieces) autoregressively.

Initialization and Pre-training

A key innovation of TrOCR is its initialization strategy. The model is not trained from a blank slate; instead, the encoder is initialized with weights from pre-trained vision models like DeiT or BEiT, while the decoder starts with weights from language models like RoBERTa or MiniLM. This allows the model to start with a sophisticated understanding of both visual structures and linguistic context.

The training follows a two-stage process:

  1. Stage 1: Pre-training on a massive synthetic dataset of 684 million printed text lines.
  2. Stage 2: Fine-tuning on smaller, task-specific synthetic datasets for handwriting or scene text, followed by final tuning on real-world, human-labeled data.

Key Results

TrOCR established new benchmarks across several major OCR datasets, demonstrating the viability of convolution-free architectures for text recognition.

Performance comparison on the SROIE dataset, showing TrOCR variants achieving superior F1 scores compared to traditional OCR models.
  • Printed Receipts (SROIE): As shown in the table above, the TrOCR-Large model reached an F1 score of 96.58%, topping the leaderboard against established commercial-grade OCR engines and traditional models like CRNN.
  • Handwriting (IAM): The model achieved a Character Error Rate (CER) of 2.89, outperforming previous state-of-the-art models that required external language models.
  • Scene Text: TrOCR set new records on 5 out of 8 benchmark datasets (including IIIT5K and SVT), showing extreme robustness to blur, distortion, and irregular fonts.
  • Efficiency: The "Small" version of the model (62M parameters) provides a balance of speed and accuracy, outperforming many larger traditional models and making it suitable for industrial deployment.

Discussion and Future Work

TrOCR proves that CNNs are not a requirement for high-quality OCR. By using Byte Pair Encoding (BPE) wordpieces instead of individual characters, the model handles larger vocabularies more efficiently and captures better semantic context through its implicit language modeling capabilities.

However, TrOCR is currently a recognition model; it assumes text has already been detected and cropped into lines. A complete OCR system still requires a separate detection module. Future research aims to extend TrOCR to multilingual support and explore "end-to-end" versions that combine text detection and recognition into a single unified Transformer framework.

Summary updated

BibTeX
@inproceedings{li2023trocr,
  author = {Minghao Li and Tengchao Lv and Jingye Chen and Lei Cui and Yijuan Lu and Dinei A. F. Florêncio and Cha Zhang and Zhoujun Li and Furu Wei},
  title = {{TrOCR: Transformer-Based Optical Character Recognition with Pre-trained Models}},
  booktitle = {AAAI Conference on Artificial Intelligence},
  year = {2023},
  doi = {10.1609/aaai.v37i11.26538},
}
Figure