{"notes":[{"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"}]},{"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-spotting/got","category":"text-spotting","legacyPath":"text-spotting/2409-got","legacySlug":"2409-got","legacyPaths":[],"title":"GOT","subtitle":"All-encompassing OCR","author":"Z. Yuan","paperDate":"2024-09-03","publishedOn":"2024-10-06","paperTitle":"General OCR Theory: Towards OCR-2.0 via a Unified End-to-end Model","paperUrl":"https://arxiv.org/abs/2409.01704","bibliography":{"title":"General OCR Theory: Towards OCR-2.0 via a Unified End-to-end Model","authors":["Haoran Wei","Chenglong Liu","Jinyue Chen","Jia Wang","Lingyu Kong","Yanming Xu","Zheng Ge","Liang Zhao","Jianjian Sun","Yuang Peng","Chunrui Han","Xiangyu Zhang"],"url":"https://arxiv.org/abs/2409.01704","pdfUrl":"https://arxiv.org/pdf/2409.01704","codeUrl":null,"preprint":{"id":"2409.01704","submittedOn":"2024-09-03","url":"https://arxiv.org/abs/2409.01704"},"publication":null,"citation":"@misc{textspottinggot2024,\n  title = {{General OCR Theory: Towards OCR-2.0 via a Unified End-to-end Model}},\n  author = {Haoran Wei and Chenglong Liu and Jinyue Chen and Jia Wang and Lingyu Kong and Yanming Xu and Zheng Ge and Liang Zhao and Jianjian Sun and Yuang Peng and Chunrui Han and Xiangyu Zhang},\n  year = {2024},\n  eprint = {2409.01704},\n  archivePrefix = {arXiv},\n  url = {https://arxiv.org/abs/2409.01704}\n}\n","citationPath":"/content/papers/citations/text-spotting/got.a6192bad407a.bib"},"thumbnail":{"src":"/content/papers/assets/7ed02fbacb92b589ea5efc9c02a180ddc03e3af515428f8db5b3a64ab0b754dd.jpg","width":1224,"height":908},"locale":"en","path":"/content/papers/en/text-spotting/got.a7bec0775c96.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":"phase-1-training","text":"Phase 1 Training","depth":3},{"id":"training-data","text":"Training Data","depth":4},{"id":"phase-2-training","text":"Phase 2 Training","depth":3},{"id":"phase-3-training","text":"Phase 3 Training","depth":3},{"id":"training-strategy","text":"Training Strategy","depth":3},{"id":"discussion","text":"Discussion","depth":2},{"id":"plain-text-document-ocr-performance","text":"Plain Text Document OCR Performance","depth":3},{"id":"scene-text-ocr-performance","text":"Scene Text OCR Performance","depth":3},{"id":"formatted-document-ocr-performance","text":"Formatted Document OCR Performance","depth":3},{"id":"fine-grained-ocr-performance","text":"Fine-grained OCR Performance","depth":3},{"id":"conclusion","text":"Conclusion","depth":2}],"anchorAliases":{},"guide":null,"relatedReading":[{"id":"text-recognition/dtrocr","relation":"comparison","topic":"Generative approaches to OCR"},{"id":"text-recognition/diffusionstr","relation":"comparison","topic":"Generative approaches to OCR"}]},{"id":"text-recognition/diffusionstr","category":"text-recognition","legacyPath":"text-recognition/2306-diffusionstr","legacySlug":"2306-diffusionstr","legacyPaths":[],"title":"DiffusionSTR","subtitle":"Text Signals Amidst Noise","author":"Z. Yuan","paperDate":"2023-06-29","publishedOn":"2024-10-13","paperTitle":"DiffusionSTR: Diffusion Model for Scene Text Recognition","paperUrl":"https://arxiv.org/abs/2306.16707","bibliography":{"title":"DiffusionSTR: Diffusion Model for Scene Text Recognition","authors":["Masato Fujitake"],"url":"https://arxiv.org/abs/2306.16707","pdfUrl":"https://arxiv.org/pdf/2306.16707","codeUrl":null,"preprint":{"id":"2306.16707","submittedOn":"2023-06-29","url":"https://arxiv.org/abs/2306.16707"},"publication":{"venue":"ICIP","year":2023,"kind":"conference","url":"https://arxiv.org/abs/2306.16707"},"citation":"@misc{textrecognitiondiffusionstr2023,\n  title = {{DiffusionSTR: Diffusion Model for Scene Text Recognition}},\n  author = {Masato Fujitake},\n  year = {2023},\n  eprint = {2306.16707},\n  archivePrefix = {arXiv},\n  url = {https://arxiv.org/abs/2306.16707}\n}\n","citationPath":"/content/papers/citations/text-recognition/diffusionstr.e8ee4c2db44d.bib"},"thumbnail":{"src":"/content/papers/assets/fe0f3bb5164b182f59bf735f76d6487408377e22beebbfe6f11bf0f6caba5afd.jpg","width":1464,"height":432},"locale":"en","path":"/content/papers/en/text-recognition/diffusionstr.e31657d2a01f.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":"transformer-architecture","text":"Transformer Architecture","depth":3},{"id":"discussion","text":"Discussion","depth":2},{"id":"comparison-with-other-methods","text":"Comparison with Other Methods","depth":3},{"id":"advantages-of-diffusion-models","text":"Advantages of Diffusion Models","depth":3},{"id":"impact-of-character-aware-head","text":"Impact of Character-Aware Head","depth":3},{"id":"effect-of-diffusion-steps","text":"Effect of Diffusion Steps","depth":3},{"id":"conclusion","text":"Conclusion","depth":2}],"anchorAliases":{},"guide":null,"relatedReading":[{"id":"text-spotting/got","relation":"comparison","topic":"Generative approaches to OCR"},{"id":"text-recognition/dtrocr","relation":"comparison","topic":"Generative approaches to OCR"}]}],"text":"This paper was authored by a Japanese OCR company, which is an uncommon group of authors in this field.\n\nThe model is named D-TrOCR, where \"Decoder-only\" is the key concept.\n\nWhen we first saw it, we couldn’t help but think of pronouncing it as \"Doctor.\" (?)\n\n## Problem Definition\n\nWe previously reviewed **TrOCR**, and you might still recall some of it.\n\n\n> [!TIP]\n> \n> If not, you can revisit our earlier article:\n> \n> - [**[21.09] TrOCR: Pretraining is Justice**](/blog/papers/text-recognition/trocr)\n\n\nTrOCR extensively employs a pretraining architecture, combining encoder and decoder models to create a complete OCR processing pipeline.\n\nHowever, the authors of this paper questioned the necessity of the encoder model for OCR tasks:\n\n- **What if we only need the decoder to accomplish OCR?**\n\nDoes this idea sound familiar?\n\nThe idea recalls the decoder-only architecture of GPT. DTrOCR tests whether the same architectural direction can handle text generation conditioned on an image.\n\nWhen writing papers, paying homage to groundbreaking ideas by applying them to different fields can often result in something remarkable. This might just be one of those cases!\n\n## Problem Solving\n\n### Model Architecture\n\n\n\n![model architecture](/content/papers/assets/192548a108c1789007d9a90f8ecb479c783d1b198a507d1742a4c8e5cbadc81a.jpg)\n\n\n\nIn simple terms, the encoder component is removed, and the image input is directly fed into the decoder.\n\nThe input image is processed through the Patch Embedding module, where it is divided into small patches and converted into vectors. Positional encodings are added to these input vectors, which are then passed to the decoder for text generation. This process is similar to the approach used in ViT.\n\nThe decoder receives these vectors and appends a special token `[SEP]` at the end. It then begins generating text starting from `[SEP]` and continues until it encounters `[EOS]`, indicating the end.\n\nText is represented by subword tokens (BPE in the implementation), and Beam Search is employed to produce the final text output.\n\nThe decoder architecture directly utilizes the pre-trained GPT-2 model, eliminating the need for training from scratch and saving a significant amount of time.\n\n### Synthetic Dataset Pretraining\n\nThe original language model is trained on large-scale text datasets, but such models are not suitable for handling OCR tasks. This is because the model lacks the ability to recognize image features and cannot associate images with text.\n\nTo address this, the authors further pre-trained the model using artificially synthesized datasets. These datasets include various types of text, such as scene text, handwritten text, and printed text.\n\nIn the TrOCR paper, the training data was annotated using PDF files and commercial OCR systems. However, this data preparation process is time-consuming and labor-intensive. Instead, the authors opted for text corpora to generate synthetic data for better reproducibility. The relevant corpora include **PILE**, **CC100**, and **Chinese NLP Corpus**.\n\nThe process of generating synthetic data is as follows:\n\n- Three open-source libraries were used to generate synthetic datasets, splitting the text corpus into three categories: scene text, printed text, and handwritten text recognition, with a distribution of 60%, 20%, and 20%, respectively.\n- For scene text recognition, 4 billion horizontal text images and 2 billion vertical text images were generated using **SynthTIGER**, utilizing default fonts for English and 64 commonly used fonts for Chinese.\n- Using SynthTIGER's multi-line text image configuration and the **MJSynth** and **SynthText** corpora, the authors generated 100 million multi-line English text images with the word count set to five.\n- For printed text recognition, 2 billion images were generated using the default settings of **TextRender**.\n- For handwritten text recognition, 2 billion images were generated using **TRDG**, leveraging 5,427 English handwriting fonts and 4 Chinese handwriting fonts.\n\n\n> [!TIP]\n> \n> For related synthetic tools, we’ve compiled a list elsewhere. If you’re interested, you can refer to:\n> \n> - [**Text Synthesis Tool Resources**](https://docsaid.org/en/docs/wordcanvas/tools)\n\n\n### Real Data Fine-Tuning\n\nTo enhance the model's adaptability in real-world environments, fine-tuning with real datasets is still necessary.\n\nThe real datasets used in the paper include: **COCO-Text**, **RCTW**, **Uber-Text**, **ArT**, **LSVT**, **MLT19**, and **ReCTS**.\n\n\n> [!TIP]\n> \n> For a related data-consolidation approach, see [**Union14M**](https://github.com/Mountchicken/Union14M). Its character coverage, source licenses, and splits do not necessarily match the English and Chinese training setup here, so it is not a drop-in replacement.\n\n\n### Implementation Details\n\n1. **Model Configuration**\n\n   - **Decoder Model**:\n\n     - Utilized English GPT-2 and Chinese GPT-2 models.\n     - Model specifications:\n       - 12-layer Transformer.\n       - Each layer has a 768-dimensional hidden size.\n       - 12 attention heads in the multi-head attention mechanism.\n     - Used Byte Pair Encoding (BPE) vocabulary.\n\n   - **Image Patch Embedding**:\n     - Following prior research, an 8 × 4 patch size was used.\n     - Relative positional encoding was applied.\n     - Maximum token length was set to 512.\n\n---\n\n2. **Training Settings**\n\n   - **Pretraining**:\n\n     - English model: Pretrained on English datasets.\n     - Chinese model: Pretrained on a combination of Chinese and English datasets.\n     - Training parameters:\n       - 1 epoch with a batch size of 32.\n       - AdamW optimizer with a learning rate of $10^{-4}$.\n\n   - **Fine-Tuning**:\n     - Initialized with pretrained weights.\n     - Fine-tuned on target datasets:\n       - Most datasets were trained for 1 epoch with a learning rate of $5 \\times 10^{-6}$.\n       - The SROIE dataset was trained for 4 epochs.\n     - The same optimizer and batch size as in pretraining were used.\n\n---\n\n3. **Data Augmentation**\n\n   - Applied RandAugment (excluding the \"Sharpness\" augmentation).\n   - Added the following augmentations:\n     - **Invert**: Color inversion.\n     - **Gaussian Blur**: Apply Gaussian blurring.\n     - **Poisson Noise**: Add Poisson noise.\n   - RandAugment configuration:\n     - Three-layer policy.\n     - Augmentation magnitude set to 5.\n   - All images were resized to 128 × 32 pixels.\n   - Retained the original image orientation and applied random rotations:\n     - Keep original orientation (95% probability).\n     - Rotate 90 degrees clockwise (2.5% probability).\n     - Rotate 90 degrees counterclockwise (2.5% probability).\n   - Normalized images to the range $[-1, 1]$.\n\n## Discussion\n\n### STR Comparison\n\n\n\n![model architecture](/content/papers/assets/b68628ca2d3557fefc65fd49272cdf1dd2f3234d032e7944ae9f246b04097ddf.jpg)\n\n\n\nThe table groups methods by training on synthetic or real data. For every reported benchmark result within each group, DTrOCR has higher word accuracy than the listed methods. Their training data and settings differ, so this table alone cannot attribute the gains to the decoder architecture.\n\nTrOCR, ABINet, PARSeq, and MaskOCR combine visual encoding and sequence modeling in different ways. DTrOCR achieves the reported accuracy without a separate visual encoder.\n\nIn the examples below, DTrOCR correctly reads occluded or irregular text and the two-line text. The other two methods make errors on these examples.\n\n\n\n![demo](/content/papers/assets/0547a1057d766a948d6499d6f48bd34d8703e314e98383e159f129f0f832af9d.jpg)\n\n\n\n### SROIE Comparison\n\n\n\n![sroie](/content/papers/assets/898e2b0f9af7fa17b573c81050a16715db262ca094645bc8628f25eae762c359.jpg)\n\n\n\nThe table reports word-level recall, precision, and F1 on SROIE Task 2. DTrOCR uses no separate CNN or ViT visual encoder and scores higher than the listed methods on all three measures.\n\n### Handwritten Performance\n\n\n\n![handwriting](/content/papers/assets/ab3f03b8dfb50e8c6474d9509ef400a2de4ed401e9711af18d9119081eb7a8f6.jpg)\n\n\n\nThe handwriting evaluation uses the IAM Handwriting Database, an area with fewer studies. The table includes Diaz et al., who use internal annotated data and an external language model, and the Transformer-based TrOCR. Their training conditions differ, so those conditions matter when interpreting the results.\n\nDTrOCR uses synthetic data and the IAM training set without an external language model. It has the lowest character error rate in the table (CER 2.38; lower is better).\n\n### CTR Performance\n\n\n\n![chinese](/content/papers/assets/8076d6de092fc9e716df1ea4a03b71cf6c931bd0b10e4678f8b2fbcd2d06690c.jpg)\n\n\n\nThe Chinese benchmark tests include four subsets: scene, web, document, and handwritten text.\n\n\n> [!TIP]\n> \n> The standards for the Chinese benchmark tests follow prior research:\n> \n> - [**[21.12] Benchmarking Chinese Text Recognition: Datasets, Baselines, and an Empirical Study**](https://arxiv.org/abs/2112.15093)\n\n\nDTrOCR has higher word accuracy than the listed methods on all four subsets. The margins are larger for scene, web, and handwriting text; on documents, it leads the next-best result by 0.5 percentage points.\n\nTrOCR uses a decoder initialized from masked-language-model (MLM) pretraining, and MaskOCR also uses MLM-based pretraining. DTrOCR instead uses generative pretraining to predict the next text token. TrOCR still generates OCR output autoregressively; the contrast here concerns pretraining, not whether its final OCR output is autoregressive.\n\nThe results support this decoder-only design for the evaluated Chinese recognition tasks; they do not isolate generative pretraining as the sole cause of the gains.\n\n## Conclusion\n\nIn this paper, the authors presented an extremely simple OCR model structure, demonstrating that OCR tasks can be accomplished effectively using only a decoder model. They validated the effectiveness of this approach.\n\nAcross multiple benchmarks, DTrOCR consistently surpassed state-of-the-art methods in accuracy and exhibited strong generalization capabilities. Moving forward, this model might evolve along the path of large language models (LLMs), focusing on improvements in speed and performance.\n\n\n> [!TIP]\n> \n> Autoregressive models generate output step by step, so decoding latency deserves attention for long strings.\n> \n> Imagine using a commercial LLM, where text appears one token at a time. If an image contains hundreds of characters, how long would you need to wait for the results?\n> \n> - Alternatively, consider this question: **How long are you willing to wait?**\n> \n> Acceptable latency depends on the application: live camera recognition, a single-page upload, and background batch processing have different needs. Measure complete-string latency, output length, and throughput before deciding whether the model fits a product.\n","imageSizes":{"/content/papers/assets/192548a108c1789007d9a90f8ecb479c783d1b198a507d1742a4c8e5cbadc81a.jpg":{"width":1224,"height":660},"/content/papers/assets/b68628ca2d3557fefc65fd49272cdf1dd2f3234d032e7944ae9f246b04097ddf.jpg":{"width":1224,"height":1004},"/content/papers/assets/0547a1057d766a948d6499d6f48bd34d8703e314e98383e159f129f0f832af9d.jpg":{"width":1032,"height":340},"/content/papers/assets/898e2b0f9af7fa17b573c81050a16715db262ca094645bc8628f25eae762c359.jpg":{"width":996,"height":456},"/content/papers/assets/ab3f03b8dfb50e8c6474d9509ef400a2de4ed401e9711af18d9119081eb7a8f6.jpg":{"width":1048,"height":452},"/content/papers/assets/8076d6de092fc9e716df1ea4a03b71cf6c931bd0b10e4678f8b2fbcd2d06690c.jpg":{"width":1224,"height":556}}}
