{"notes":[{"id":"text-recognition/trocr","category":"text-recognition","legacyPath":"text-recognition/2109-trocr","legacySlug":"2109-trocr","legacyPaths":[],"title":"TrOCR","subtitle":"Pretraining is Justice","author":"Z. Yuan","paperDate":"2021-09-21","publishedOn":"2024-11-14","paperTitle":"TrOCR: Transformer-based Optical Character Recognition with Pre-trained Models","paperUrl":"https://arxiv.org/abs/2109.10282","bibliography":{"title":"TrOCR: Transformer-based Optical Character Recognition with Pre-trained Models","authors":["Minghao Li","Tengchao Lv","Jingye Chen","Lei Cui","Yijuan Lu","Dinei Florencio","Cha Zhang","Zhoujun Li","Furu Wei"],"url":"https://arxiv.org/abs/2109.10282","pdfUrl":"https://arxiv.org/pdf/2109.10282","codeUrl":null,"preprint":{"id":"2109.10282","submittedOn":"2021-09-21","url":"https://arxiv.org/abs/2109.10282"},"publication":{"venue":"AAAI","year":2023,"kind":"conference","url":"https://doi.org/10.1609/aaai.v37i11.26538"},"citation":"@misc{textrecognitiontrocr2021,\n  title = {{TrOCR: Transformer-based Optical Character Recognition with Pre-trained Models}},\n  author = {Minghao Li and Tengchao Lv and Jingye Chen and Lei Cui and Yijuan Lu and Dinei Florencio and Cha Zhang and Zhoujun Li and Furu Wei},\n  year = {2021},\n  eprint = {2109.10282},\n  archivePrefix = {arXiv},\n  url = {https://arxiv.org/abs/2109.10282}\n}\n","citationPath":"/content/papers/citations/text-recognition/trocr.d9bddea6d391.bib"},"thumbnail":{"src":"/content/papers/assets/db1ff0ed555fdeb39b350f209fc898c08ae78ce212dff807d975f969e8d57e46.jpg","width":1452,"height":650},"locale":"en","path":"/content/papers/en/text-recognition/trocr.9cfe61af980a.md","headings":[{"id":"problem-definition","text":"Problem Definition","depth":2},{"id":"solution","text":"Solution","depth":2},{"id":"model-architecture","text":"Model Architecture","depth":3},{"id":"training-strategy","text":"Training Strategy","depth":3},{"id":"parameter-settings","text":"Parameter Settings","depth":3},{"id":"discussion","text":"Discussion","depth":2},{"id":"encoder-decoder-combinations","text":"Encoder-Decoder Combinations","depth":3},{"id":"performance-on-the-sroie-dataset","text":"Performance on the SROIE Dataset","depth":3},{"id":"performance-on-the-iam-dataset","text":"Performance on the IAM Dataset","depth":3},{"id":"performance-on-str","text":"Performance on STR","depth":3},{"id":"conclusion","text":"Conclusion","depth":2}],"anchorAliases":{},"guide":null,"relatedReading":[{"id":"text-recognition/vitstr","relation":"background","topic":"Pretraining Transformers for text recognition"},{"id":"text-recognition/dtrocr","relation":"next","topic":"Pretraining Transformers for text recognition"}]},{"id":"text-recognition/vitstr","category":"text-recognition","legacyPath":"text-recognition/2105-vitstr","legacySlug":"2105-vitstr","legacyPaths":[],"title":"ViTSTR","subtitle":"Encoder-Only Model","author":"Z. Yuan","paperDate":"2021-05-18","publishedOn":"2024-10-14","paperTitle":"Vision Transformer for Fast and Efficient Scene Text Recognition","paperUrl":"https://arxiv.org/abs/2105.08582","bibliography":{"title":"Vision Transformer for Fast and Efficient Scene Text Recognition","authors":["Rowel Atienza"],"url":"https://arxiv.org/abs/2105.08582","pdfUrl":"https://arxiv.org/pdf/2105.08582","codeUrl":null,"preprint":{"id":"2105.08582","submittedOn":"2021-05-18","url":"https://arxiv.org/abs/2105.08582"},"publication":{"venue":"ICDAR","year":2021,"kind":"conference","url":"https://arxiv.org/abs/2105.08582"},"citation":"@misc{textrecognitionvitstr2021,\n  title = {{Vision Transformer for Fast and Efficient Scene Text Recognition}},\n  author = {Rowel Atienza},\n  year = {2021},\n  eprint = {2105.08582},\n  archivePrefix = {arXiv},\n  url = {https://arxiv.org/abs/2105.08582}\n}\n","citationPath":"/content/papers/citations/text-recognition/vitstr.1fbbe0faa172.bib"},"thumbnail":{"src":"/content/papers/assets/8b45a393dfec527588d0cad43a28fbc97722d4a3b57b92b79373910f367d4c0a.jpg","width":1160,"height":536},"locale":"en","path":"/content/papers/en/text-recognition/vitstr.9a7abc18daa0.md","headings":[{"id":"defining-the-problem","text":"Defining the Problem","depth":2},{"id":"problem-solution","text":"Problem Solution","depth":2},{"id":"model-architecture","text":"Model Architecture","depth":3},{"id":"model-training-configuration","text":"Model Training Configuration","depth":3},{"id":"discussion","text":"Discussion","depth":2},{"id":"comparison-with-other-models","text":"Comparison with Other Models","depth":3},{"id":"performance-trade-offs","text":"Performance Trade-offs","depth":3},{"id":"conclusion","text":"Conclusion","depth":2}],"anchorAliases":{},"guide":null,"relatedReading":[{"id":"text-recognition/trocr","relation":"next","topic":"Pretraining Transformers for text recognition"}]},{"id":"text-recognition/dtrocr","category":"text-recognition","legacyPath":"text-recognition/2308-dtrocr","legacySlug":"2308-dtrocr","legacyPaths":[],"title":"DTrOCR","subtitle":"Decoder-Only Approach","author":"Z. Yuan","paperDate":"2023-08-30","publishedOn":"2024-11-15","paperTitle":"DTrOCR: Decoder-only Transformer for Optical Character Recognition","paperUrl":"https://arxiv.org/abs/2308.15996","bibliography":{"title":"DTrOCR: Decoder-only Transformer for Optical Character Recognition","authors":["Masato Fujitake"],"url":"https://arxiv.org/abs/2308.15996","pdfUrl":"https://arxiv.org/pdf/2308.15996","codeUrl":null,"preprint":{"id":"2308.15996","submittedOn":"2023-08-30","url":"https://arxiv.org/abs/2308.15996"},"publication":{"venue":"WACV","year":2024,"kind":"conference","url":"https://arxiv.org/abs/2308.15996"},"citation":"@misc{textrecognitiondtrocr2023,\n  title = {{DTrOCR: Decoder-only Transformer for Optical Character Recognition}},\n  author = {Masato Fujitake},\n  year = {2023},\n  eprint = {2308.15996},\n  archivePrefix = {arXiv},\n  url = {https://arxiv.org/abs/2308.15996}\n}\n","citationPath":"/content/papers/citations/text-recognition/dtrocr.dcb015457224.bib"},"thumbnail":{"src":"/content/papers/assets/192548a108c1789007d9a90f8ecb479c783d1b198a507d1742a4c8e5cbadc81a.jpg","width":1224,"height":660},"locale":"en","path":"/content/papers/en/text-recognition/dtrocr.f34ff9819780.md","headings":[{"id":"problem-definition","text":"Problem Definition","depth":2},{"id":"problem-solving","text":"Problem Solving","depth":2},{"id":"model-architecture","text":"Model Architecture","depth":3},{"id":"synthetic-dataset-pretraining","text":"Synthetic Dataset Pretraining","depth":3},{"id":"real-data-fine-tuning","text":"Real Data Fine-Tuning","depth":3},{"id":"implementation-details","text":"Implementation Details","depth":3},{"id":"discussion","text":"Discussion","depth":2},{"id":"str-comparison","text":"STR Comparison","depth":3},{"id":"sroie-comparison","text":"SROIE Comparison","depth":3},{"id":"handwritten-performance","text":"Handwritten Performance","depth":3},{"id":"ctr-performance","text":"CTR Performance","depth":3},{"id":"conclusion","text":"Conclusion","depth":2}],"anchorAliases":{"real-dataset-pretraining":"real-data-fine-tuning"},"guide":null,"relatedReading":[{"id":"text-recognition/trocr","relation":"background","topic":"Pretraining Transformers for text recognition"},{"id":"text-spotting/got","relation":"comparison","topic":"Generative approaches to OCR"},{"id":"text-recognition/diffusionstr","relation":"comparison","topic":"Generative approaches to OCR"}]}],"text":"This is a straightforward paper, ideal for developers who are new to this field and looking for a clear entry point.\n\n## Problem Definition\n\nAt the time, many OCR systems still used CNN backbones, adding Transformer self-attention to better understand text images. CTC handled sequence alignment in some recognition systems, and an external language model could improve their predictions; these played different roles.\n\nAlthough these methods have seen some success, most models are still trained from scratch and do not fully utilize the advantages of large-scale pre-trained models in computer vision (CV) and natural language processing (NLP).\n\nIn this paper, the authors lead by example, showing how pre-trained models can be applied effectively to OCR tasks.\n\n\n> [!TIP]\n> \n> Some experiments had found models trained from scratch performed better, so some researchers doubted that pretraining would make much difference for OCR. This paper puts that question to a concrete test.\n\n\n## Solution\n\n### Model Architecture\n\n\n\n![model arch](/content/papers/assets/db1ff0ed555fdeb39b350f209fc898c08ae78ce212dff807d975f969e8d57e46.jpg)\n\n\n\nThe TrOCR model is composed of two parts: an image Transformer and a text Transformer.\n\n\n> [!TIP]\n> \n> This architecture is very straightforward, based on the foundational Transformer model. If you're not yet familiar with the Transformer architecture, we recommend referring to our previous article:\n> \n> - [**[17.06] Transformer: The Dawn of a New Era**](/blog/papers/transformers/transformer)\n> - [**[20.10] ViT: Pioneering a New World**](/blog/papers/vision-transformers/vit)\n\n\nUnlike traditional text recognition models, TrOCR doesn’t rely on a CNN backbone. Instead, it follows the approach used in ViT, resizing the input image to $384 \\times 384$ and then splitting it into $16 \\times 16$ patches before feeding it into the image encoder. Both the encoder and decoder use a standard Transformer architecture, with wordpiece units as the output for recognized text.\n\nFor the experiments, the image encoder is initialized from the ViT-style DeiT or BEiT models, and the decoder from RoBERTa or MiniLM. The decoder must use causal self-attention for OCR generation; its encoder-decoder cross-attention parameters are absent from those pretrained models and are initialized randomly.\n\n\n> [!TIP]\n> \n> Here are some key takeaways:\n> \n> 1. **There is no need to invent another backbone here: reuse ViT-style and BERT-style pretrained models.**\n> 2. **The output format isn’t character-based but instead uses wordpiece units.**\n> \n> If these pre-trained models are new to you, check out our previous readings:\n> \n> - [**[18.10] BERT: Twelve Layers of Encoders**](/blog/papers/transformers/bert)\n> - [**[19.07] RoBERTa: A Guide to Training BERT**](/blog/papers/transformers/roberta)\n> - [**[20.12] DeiT: Distillation ViT**](/blog/papers/vision-transformers/deit)\n> - [**[21.06] BEiT: Discrete Encoding Pre-Training**](/blog/papers/vision-transformers/beit)\n\n\n### Training Strategy\n\n- **Phase One**\n\n  In the first phase of pre-training, the authors sampled two million pages from publicly available PDF files. These PDFs were converted into page images, and each text line was extracted to create a dataset of 684 million text line images. Since these PDFs are “digitally generated,” they offer high clarity in the text images.\n\n- **Phase Two**\n\n  Using the open-source text generator TRDG and 5,427 handwritten fonts, the authors synthesized handwritten text line images with text content randomly drawn from Wikipedia pages. This stage generated a dataset of 17.9 million text lines, including the IIIT-HWS dataset.\n\n  Additionally, around 53,000 real-world receipt images were collected. A commercial OCR engine recognized the text on these images, and each text line was cropped and normalized based on its coordinates.\n\n  Finally, TRDG was used to generate around one million printed text line images with receipt fonts and other built-in fonts, resulting in a printed dataset with 3.3 million text lines.\n\n  For scene text recognition, the second phase used the MJSynth and SynthText datasets, comprising about 16 million text images in total.\n\n\n> [!TIP]\n> \n> TRDG is an open-source text image generator that can be used to create synthetic text images for training OCR models.\n> \n> You can find more information about TRDG at [TextRecognitionDataGenerator](https://github.com/Belval/TextRecognitionDataGenerator)\n\n\n### Parameter Settings\n\nThe image branch of TrOCR uses DeiT and BEiT models, while the text branch uses RoBERTa or MiniLM.\n\nThe DeiT model implementation and pre-trained weights come from the `timm` library, the BEiT and MiniLM models are from the official UniLM repository, and the RoBERTa model is sourced from Fairseq’s GitHub repository.\n\n\n> [!TIP]\n> \n> timm is a PyTorch library that provides efficient and modular implementations of vision models.\n> \n> You can find more information about timm at [**pytorch-image-models**](https://github.com/huggingface/pytorch-image-models)\n\n\nTraining is conducted using 32 V100 GPUs for pre-training and 8 V100 GPUs for fine-tuning. All models use a batch size of 2,048 and a learning rate of $5 \\times 10^{-5}$.\n\nThe following details outline additional parameter settings:\n\n- **Resolution and Patch Size**: DeiT and BEiT encoders use an image resolution of $384 \\times 384$, with a patch size of $16 \\times 16$.\n- **Encoder Architecture**:\n  - $\\text{DeiT}_{\\text{SMALL}}$: 12 layers, 384-dimensional hidden size, 6 attention heads.\n  - $\\text{DeiT}_{\\text{BASE}}$ and $\\text{BEiT}_{\\text{BASE}}$: 12 layers, 768-dimensional hidden size, 12 attention heads.\n  - $\\text{BEiT}_{\\text{LARGE}}$: 24 layers, 1024-dimensional hidden size, 16 attention heads.\n- **Decoder Architecture**:\n  - Small decoder: 6 layers, 256-dimensional hidden size, 8 attention heads.\n  - Base decoder: 512-dimensional hidden size.\n  - Large decoder: 12 layers, 1024-dimensional hidden size, 16 attention heads.\n\n## Discussion\n\n### Encoder-Decoder Combinations\n\nGiven the variety of encoder and decoder options available, which combination performs best?\n\nThe authors conducted experiments to evaluate different encoder-decoder pairings using the SROIE dataset. The results are summarized in the table below:\n\n\n\n![encoder-decoder](/content/papers/assets/08c4c640358fa224454124d81fb5f67901112e3ca99c635321ff84a54d3bea19.jpg)\n\n\n\nFor encoders, the authors tested DeiT, BEiT, and ResNet-50; for decoders, they used RoBERTa.\n\nIn this architecture comparison trained only on SROIE, the BEiT$_{\\text{BASE}}$ encoder with the RoBERTa$_{\\text{LARGE}}$ decoder has the highest F1 score, **79.36%**. The separate ablation table tests the gains from pretrained initialization and the two pretraining stages.\n\nBased on these findings, the authors selected three primary configurations for further experiments:\n\n- **TrOCR$_{\\text{SMALL}}$**: Composed of the DeiT$_{\\text{SMALL}}$ encoder and MiniLM decoder (62M parameters).\n- **TrOCR$_{\\text{BASE}}$**: Composed of the BEiT$_{\\text{BASE}}$ encoder and RoBERTa$_{\\text{LARGE}}$ decoder (334M parameters).\n- **TrOCR$_{\\text{LARGE}}$**: Composed of the BEiT$_{\\text{LARGE}}$ encoder and RoBERTa$_{\\text{LARGE}}$ decoder (558M parameters).\n\n### Performance on the SROIE Dataset\n\n\n\n![sroie](/content/papers/assets/ba8574c728abf5dea239c1db67f0b1583f49848b4f4ae98b95c283e31324aa5b.jpg)\n\n\n\nThe table above compares TrOCR models with other methods on SROIE. It evaluates text-line images cropped using ground-truth boxes, without measuring text detection.\n\nIn terms of language modeling, MSO Lab and CLOVA OCR models use LSTM layers, while H&H Lab uses GRU layers. In contrast, TrOCR utilizes a pure attention-based Transformer decoder.\n\nTrOCR$_{\\text{LARGE}}$ reaches **96.58% F1** on this text-line recognition task, slightly above H&H Lab's **96.43%**, without complex additional recognition post-processing.\n\n### Performance on the IAM Dataset\n\n\n\n![iam](/content/papers/assets/0dee9079d77312750cf426b3505290d8a6fc593e757d4847deaf6082e21c659c.jpg)\n\n\n\nThe table above compares the performance of TrOCR models to existing methods on the IAM handwriting dataset.\n\nFor Diaz et al.'s CTC model, adding an external language model (LM) lowers the character error rate (CER) from **3.53% to 2.75%**. TrOCR$_{\\text{LARGE}}$ reaches **2.89% CER** without an external LM. That is below Bluche and Messina's CTC result of **3.20%**, but above Diaz et al.'s result with its extra internal data and LM; the training data also differ between methods.\n\n### Performance on STR\n\n\n\n![str](/content/papers/assets/b9bebcb63df2008f70b51c20caa306edbf4b6a22ec55b753511b4d1a34cf83a0.jpg)\n\n\n\nThe performance of TrOCR was evaluated with fine-tuning on synthetic data alone, as well as fine-tuning on both synthetic and benchmark datasets (IC13, IC15, IIIT5K, SVT training sets). The results were then compared to existing mainstream and recent SOTA methods.\n\nIn the table's eight test columns, TrOCR fine-tuned on **synthetic plus benchmark training data** has the highest listed result on SVT, both IC13 subsets, SVTP, and CUTE. It does not lead on IIIT5K or either IC15 subset.\n\n\n> [!NOTE]\n> \n> TrOCR underperformed on the IIIT5K dataset.\n> \n> The authors analyzed this outcome and found that some scene text samples contain symbols, whereas the ground truth labels did not include these symbols. This inconsistency with the pre-training data (where symbols were retained in the ground truth) caused the model to tend toward symbol recognition.\n\n\n## Conclusion\n\nThe key distinction of TrOCR from previous studies is its use of pre-trained models.\n\nBy making full use of pretrained models, the authors build a relatively simple Transformer encoder-decoder without a CNN backbone. The results show its potential across printed, handwritten, and scene-text recognition. The architecture is simpler to describe and maintain, although these results alone do not show that every TrOCR setting uses less computation than earlier models.\n","imageSizes":{"/content/papers/assets/db1ff0ed555fdeb39b350f209fc898c08ae78ce212dff807d975f969e8d57e46.jpg":{"width":1452,"height":650},"/content/papers/assets/08c4c640358fa224454124d81fb5f67901112e3ca99c635321ff84a54d3bea19.jpg":{"width":1048,"height":340},"/content/papers/assets/ba8574c728abf5dea239c1db67f0b1583f49848b4f4ae98b95c283e31324aa5b.jpg":{"width":852,"height":464},"/content/papers/assets/0dee9079d77312750cf426b3505290d8a6fc593e757d4847deaf6082e21c659c.jpg":{"width":1224,"height":400},"/content/papers/assets/b9bebcb63df2008f70b51c20caa306edbf4b6a22ec55b753511b4d1a34cf83a0.jpg":{"width":1224,"height":920}}}
