Back to paper library
arXiv 2021ICDAR 2021Text recognitionPaper notes

ViTSTR

Encoder-Only Model

Original paper

Vision Transformer for Fast and Efficient Scene Text Recognition

Paper authors

Rowel Atienza

Publication
ICDAR 2021Conference
First submitted to arXiv
arXiv:2105.08582
Cite this paper · BibTeX

The citation identifies the linked source version. It cites the original paper and its authors.

@misc{textrecognitionvitstr2021,
  title = {{Vision Transformer for Fast and Efficient Scene Text Recognition}},
  author = {Rowel Atienza},
  year = {2021},
  eprint = {2105.08582},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2105.08582}
}
On this page

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.

Defining the Problem

Let’s first revisit a classic STR architecture, which looks something like this:

An 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.

With the introduction of the Transformer architecture, researchers started applying it to STR. The architecture evolved into something like this:

In this setup, the encoder part could be a CNN, a Transformer, or another algorithm, but the decoder consistently became a Transformer decoder.

Regardless 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.

The authors of ViTSTR propose that if we are already using a Transformer, why not directly output the result after encoding?

Look at the ViT model—it does exactly that.

We just need to modify the architecture like this:

By 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.

Problem Solution

Model Architecture

The 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.

The input image has dimensions of x∈RH×W×Cx \in \mathbb{R}^{H \times W \times C}, where HH and WW are the height and width of the image, and CC is the number of channels. The image is reshaped into a sequence of flattened 2D patches xp∈RN×P2Cx_p \in \mathbb{R}^{N \times P^2C}, where each patch has dimensions of P×PP \times P and the sequence length is NN.

The flattened patches are projected to dimension DD. A learnable class embedding, corresponding to the [GO]\text{[GO]} output position, is prepended to the sequence. Positional encodings are then added to form the encoder inputs.

ViTSTR 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. [GO]\text{[GO]} marks the start of a text sequence, while [s]\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.

Model Training Configuration

The 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.

The baseline training conditions are shown below. ViTSTR uses the same comparison framework, but its input size changes to 224 × 224:

The authors retrained several powerful baseline models—CRNN, R2AM, GCRNN, Rosetta, RARE, STAR-Net, and TRBA—to compare them fairly with ViTSTR.

Each 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.

ViTSTR used pretrained weights from the DeiT model, and the input image size was adjusted to 224×224224 \times 224 to match the dimensions required by DeiT. No parameters were frozen during training.

Discussion

Comparison with Other Models

During 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:

The authors compared the results with and without augmentation:

Accuracy 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.

The most significant improvements were seen in irregular datasets:

DatasetViTSTR-Tiny (pp)ViTSTR-Small (pp)ViTSTR-Base (pp)
CT+9.2+6.6+6.6
SVTP+3.8+3.3+1.8
IC15 1,811+2.7+2.6+1.7
IC15 2,077+2.5+2.2+1.5

Performance Trade-offs

In 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.

Comparing 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.

In 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.

Moving from tiny to base raises unaugmented accuracy by 3.4 percentage points but adds 80.4 million parameters.

On 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.

Compared 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.

Conclusion

ViTSTR 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.