{"notes":[{"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/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"}]}],"text":"The Vision Transformer (ViT) architecture is widely known, but it seems that the scene text recognition (STR) field still lacks a defining use case for it.\n\n## Defining the Problem\n\nLet’s first revisit a classic STR architecture, which looks something like this:\n\n\n\n![old arch](/content/papers/assets/0d2d3a3c7521bf225e1ba37e7d8b7af7d29ea94cf75d9b7b5af7d03b4908f3a3.jpg)\n\n\n\nAn input image is passed through a CNN to extract features, then into an LSTM for sequence decoding, and finally through a prediction module to obtain the final result.\n\nWith the introduction of the Transformer architecture, researchers started applying it to STR. The architecture evolved into something like this:\n\n\n\n![transformer arch](/content/papers/assets/f2732dbaaa675164cf8efb00b787b0bce640e5f09303f33e4677219b5a36db5f.jpg)\n\n\n\nIn this setup, the encoder part could be a CNN, a Transformer, or another algorithm, but the decoder consistently became a Transformer decoder.\n\nRegardless of whether we use an autoregressive approach for inference, during training, the model can expand in parallel without waiting for the previous time step's output. This significantly improves efficiency.\n\nThe authors of ViTSTR propose that if we are already using a Transformer, why not directly output the result after encoding?\n\nLook at the ViT model—it does exactly that.\n\n- [**[20.10] ViT: Pioneering a New World**](/blog/papers/vision-transformers/vit)\n\nWe just need to modify the architecture like this:\n\n\n\n![encoder arch](/content/papers/assets/7beb2e5dc944eb401860bf5a5b592d599c1f89d093879b5c06852d0b54e63224.jpg)\n\n\n\nBy eliminating the decoder, we reduce the number of parameters, and we no longer need to worry about autoregressive problems. This leads to a model that is both faster and better—at least in theory. Experimental results will validate whether it's truly effective.\n\n## Problem Solution\n\n### Model Architecture\n\n![model arch](/content/papers/assets/8b45a393dfec527588d0cad43a28fbc97722d4a3b57b92b79373910f367d4c0a.jpg)\n\nThe authors propose ViTSTR, a model for STR based on the ViT architecture. The main difference lies in the prediction head. While ViT outputs an image-level class prediction, ViTSTR is for recognizing multiple characters, where the correct character sequence and length must be considered.\n\nThe input image has dimensions of $x \\in \\mathbb{R}^{H \\times W \\times C}$, where $H$ and $W$ are the height and width of the image, and $C$ is the number of channels. The image is reshaped into a sequence of flattened 2D patches $x_p \\in \\mathbb{R}^{N \\times P^2C}$, where each patch has dimensions of $P \\times P$ and the sequence length is $N$.\n\nThe flattened patches are projected to dimension $D$. A learnable class embedding, corresponding to the $\\text{[GO]}$ output position, is prepended to the sequence. Positional encodings are then added to form the encoder inputs.\n\nViTSTR uses learnable positional encodings. At the output, it extracts enough feature vectors for the maximum text length plus two marker positions and predicts their characters in parallel. $\\text{[GO]}$ marks the start of a text sequence, while $\\text{[s]}$ marks a space or the end and repeats after the text. They are symbols in the predicted sequence, rather than two extra tokens appended to the image input.\n\n\n> [!TIP]\n> \n> Essentially, it is the same as ViT.\n> \n> The detailed computations are identical to the Transformer architecture and are omitted here for brevity.\n\n\n### Model Training Configuration\n\n![model config](/content/papers/assets/4dbbce3c272d090f90b97eecbcd51f5896cf5f9fc276735ba74be5dc8a37748a.jpg)\n\nThe authors use three model configurations: ViTSTR-Tiny, ViTSTR-Small, and ViTSTR-Base. All three use 12 encoder layers, 16 × 16 patches and a prediction sequence length of 27. Their embedding widths and attention-head counts differ.\n\nThe baseline training conditions are shown below. ViTSTR uses the same comparison framework, but its input size changes to 224 × 224:\n\n![training config](/content/papers/assets/c5cfda6db0d72e08ccf82b0c6009a31debea5b5ce85a7606a1ccd060c2a8915c.jpg)\n\nThe authors retrained several powerful baseline models—CRNN, R2AM, GCRNN, Rosetta, RARE, STAR-Net, and TRBA—to compare them fairly with ViTSTR.\n\nEach model was trained at least five times with different random seeds. The paper says it saved the weights that performed best on the test sets to obtain mean evaluation scores. Since test performance influenced weight selection, those scores may be optimistic; this was not selection on an independent validation set.\n\nViTSTR used pretrained weights from the DeiT model, and the input image size was adjusted to $224 \\times 224$ to match the dimensions required by DeiT. No parameters were frozen during training.\n\n\n> [!TIP]\n> \n> Typically, the input image size for text recognition is around $32 \\times 100$.\n> \n> Using $224 \\times 224$ images here seems somewhat excessive.\n\n\n## Discussion\n\n### Comparison with Other Models\n\nDuring training, the authors used RandAugment for image augmentation, which included flipping, bending, blurring, adding noise, distorting, rotating, stretching, compressing, applying perspective transformations, and shrinking. The effects are illustrated below:\n\n![augment](/content/papers/assets/587b50a99e159847d189b17525a0910b8208864c551e616726ca26f5da2a9a84.jpg)\n\nThe authors compared the results with and without augmentation:\n\n![compare](/content/papers/assets/09c40930abe42f23d1e3757bf2f157e0989cb9372cb9bd21044b5d48eef7d471.jpg)\n\nAccuracy increased by 1.8, 1.6, and 1.5 percentage points for ViTSTR-Tiny, Small, and Base, respectively. The table below also reports percentage-point changes.\n\nThe most significant improvements were seen in irregular datasets:\n\n| Dataset    | ViTSTR-Tiny (pp) | ViTSTR-Small (pp) | ViTSTR-Base (pp) |\n| ---------- | --------------- | ---------------- | --------------- |\n| CT         | +9.2            | +6.6             | +6.6            |\n| SVTP       | +3.8            | +3.3             | +1.8            |\n| IC15 1,811 | +2.7            | +2.6             | +1.7            |\n| IC15 2,077 | +2.5            | +2.2             | +1.5            |\n\n### Performance Trade-offs\n\n![loss](/content/papers/assets/bf25169b6cc02bd0cc1d758c5d80561ba3a186470733e859b1c63246e29e67a6.jpg)\n\nIn scene text recognition, adding a stage can improve accuracy while increasing runtime and computation. In this table, TRBA scores 2.2 percentage points above RARE, has 38.8 million more parameters, and takes 4 ms longer per image. The models differ in more than one stage, however.\n\nComparing STAR-Net with TRBA, which uses Attention instead of CTC in its prediction stage, runtime rises from 8.8 to 22.8 ms per image, about 2.6 times as long, for a 2.5-percentage-point accuracy gain. The table measures the complete models, so it cannot isolate the cost of changing that stage.\n\nIn ViTSTR, upgrading from tiny to small increases embedding width and the number of heads without adding a stage. In the unaugmented results, accuracy improves by 2.3 percentage points at the cost of 16.1 million more parameters.\n\nMoving from tiny to base raises unaugmented accuracy by 3.4 percentage points but adds 80.4 million parameters.\n\nOn the paper's 2080 Ti, ViTSTR takes 9.3 ms per image for tiny, 9.5 ms for small, and 9.8 ms for base. Its MLP and self-attention layers retain the same parallel operations, while each step up adds 0.2–0.3 ms and requires more parameters and computation.\n\nCompared with the multi-stage STR models in this table, scaling ViTSTR adds no new stage and has a small measured latency increase under this hardware and input setup.\n\n## Conclusion\n\n![conclusion](/content/papers/assets/2bced239f2c6133f54a7d1280fde6627430912ae19953aa227fc0aa29b8e1511.jpg)\n\nViTSTR is a simple, single-stage model architecture that balances accuracy, speed, and computational requirements. With data augmentation tailored for STR, ViTSTR significantly improves accuracy, especially on irregular datasets. As it scales, ViTSTR continues to balance precision, speed, and computational demands.\n\n\n> [!TIP]\n> \n> It would be interesting to see what happens if we train from scratch with $32 \\times 100$ feature maps instead of using DeiT’s pretrained weights and larger input sizes.\n> \n> Maybe one day, when there's time, we’ll test that out.\n","imageSizes":{"/content/papers/assets/0d2d3a3c7521bf225e1ba37e7d8b7af7d29ea94cf75d9b7b5af7d03b4908f3a3.jpg":{"width":700,"height":304},"/content/papers/assets/f2732dbaaa675164cf8efb00b787b0bce640e5f09303f33e4677219b5a36db5f.jpg":{"width":700,"height":304},"/content/papers/assets/7beb2e5dc944eb401860bf5a5b592d599c1f89d093879b5c06852d0b54e63224.jpg":{"width":700,"height":162},"/content/papers/assets/8b45a393dfec527588d0cad43a28fbc97722d4a3b57b92b79373910f367d4c0a.jpg":{"width":1160,"height":536},"/content/papers/assets/4dbbce3c272d090f90b97eecbcd51f5896cf5f9fc276735ba74be5dc8a37748a.jpg":{"width":1000,"height":244},"/content/papers/assets/c5cfda6db0d72e08ccf82b0c6009a31debea5b5ce85a7606a1ccd060c2a8915c.jpg":{"width":1044,"height":284},"/content/papers/assets/587b50a99e159847d189b17525a0910b8208864c551e616726ca26f5da2a9a84.jpg":{"width":1224,"height":276},"/content/papers/assets/09c40930abe42f23d1e3757bf2f157e0989cb9372cb9bd21044b5d48eef7d471.jpg":{"width":1212,"height":596},"/content/papers/assets/bf25169b6cc02bd0cc1d758c5d80561ba3a186470733e859b1c63246e29e67a6.jpg":{"width":928,"height":588},"/content/papers/assets/2bced239f2c6133f54a7d1280fde6627430912ae19953aa227fc0aa29b8e1511.jpg":{"width":1224,"height":316}}}
