Scene Text Recognition with Permuted Autoregressive Sequence Models
- Publication
- ECCV 2022Conference
- First submitted to arXiv
- arXiv:2207.06966
Cite this paper · BibTeX
The citation identifies the linked source version. It cites the original paper and its authors.
@misc{textrecognitionparseq2022,
title = {{Scene Text Recognition with Permuted Autoregressive Sequence Models}},
author = {Darwin Bautista and Rowel Atienza},
year = {2022},
eprint = {2207.06966},
archivePrefix = {arXiv},
url = {https://arxiv.org/abs/2207.06966}
}
You might have noticed that the subtitle’s text is scrambled.
Or… maybe you didn’t notice at all.
Defining the Problem
Research into word order manipulation has been actively explored in recent years.
XLNet trains with different autoregressive factorization orders using two-stream attention. In STR, ABINet also uses bidirectional linguistic context, but its BCN applies a cloze mask excluding the current position; that is not permutation language modeling.
If you’d prefer a quick refresher, here’s a summary:
The concept behind the two-stream attention mechanism has a few key ideas. First, it uses “self-masking,” similar to Masked Language Modeling (MLM), where words are masked, and the model learns to predict them. The difference is that while MLM uses a special token to represent masked words, the two-stream mechanism retains positional information but masks semantic information. This enables the model to focus on predicting the final output based on meaning.
“Permutation” changes which other token positions may serve as context when predicting a target. The characters retain their original positions and the target text stays the same. What changes is the conditional prediction order, not the spelling or reading order of the image.
The authors of this paper build on these ideas to design a new STR model. “PAR” in PARSeq stands for “Permuted Autoregressive,” which highlights the idea of “permutation” in autoregressive modeling to boost performance.
If the summary above makes sense, you’ve basically understood this paper.
Solving the Problem
Model Architecture
The model architecture may seem complex at first glance, so let’s break it down step by step:
Encoder Design
If you’re familiar with the Vision Transformer (ViT) paper, this part should be straightforward.
First, let’s look at the “ViT Encoder” in the diagram above. This component converts images into tokens, then extracts features using the Transformer’s encoder.
For an image (width , height , and channels ), it’s divided into patches, each flattened and then embedded into -dimensional tokens. Finally, positional embeddings are added to these tokens.
All output tokens from the ViT serve as inputs to the decoder, represented by .
Once the image features have been processed by the encoder, they proceed to the next stage, the cross-attention decoder, highlighted in green above. After passing through the MLP in the output layer, the model generates its final predictions.
Decoder Design
As shown above, to generate output via the decoder, we start with a set of special tokens that represent the “positions,” indicating where the decoder will produce outputs.
If we mask certain parts, we see a basic decoder structure. At this point, the model’s architecture appears fairly standard, similar to previous STR models we’ve seen.
So, how do we integrate a language model into this structure?
Review
As shown above, in ABINet, the output from the vision branch is passed to the language model for "correction," producing the output of the language branch. Finally, features from both branches are combined to yield the final result.
In PARSeq, the decoder uses text context and image features together. It does not need separate language-model and fusion branches.
Permutation Language Modeling
The core concept of PARSeq is Permutation Language Modeling (PLM).
Before querying the image through cross-attention, positional queries attend to the permitted text context. A permutation mask changes which context positions are visible without physically scrambling the target string.
The PLM objective considers all possible conditioning orders. For a sequence with elements, there are possible permutations. Its objective function is:
Implementing PLM in Transformers does not require physically rearranging the label sequence . Instead, it’s achieved by adjusting the attention mask, as shown in the table below:
The full permutation space grows factorially with . Training samples orders instead: the forward order and random orders, followed by the reverse of each, giving orders in total.
Decoding Methods
PLM training, combined with proper parameterization, enables PARSeq to support multiple decoding methods.
The authors focus primarily on two contrasting decoding methods: Autoregressive (AR) and Non-autoregressive (NAR) decoding, as well as a technique called Iterative Refinement.
-
Table (a): Autoregressive (AR) Decoding
- AR decoding generates one new token per iteration.
- A left-to-right attention mask is applied.
- In the first iteration, the context is set to the start token , using only the first positional query token .
- For the -th iteration, the position queries are used, and the context is set to the previous output (using the argmax value) prepended with the start token .
-
Table (b): Non-autoregressive (NAR) Decoding
- NAR decoding generates all output tokens simultaneously.
- All positional queries are used without an attention mask.
- The context is always the start token .
-
Table (c): Iterative Refinement
- Iterative refinement can be performed regardless of whether AR or NAR decoding is used initially. Each iteration uses the previous output (truncated at the end token ) as the current context, similar to AR decoding.
- All positional queries are used, with a cloze-style mask applied.
- For each target position, the cloze mask hides that position’s own predicted character while allowing the other positions as context. It does not need to know which predictions are correct.
Loss Function
The model computes an output and a cross-entropy loss under each permutation mask. With permutations, the training loss is the average of those losses:
During training, padding tokens are ignored. Permutations change the available context, while the target characters retain their original positions.
Experimental Setup
All models are trained on a dual-GPU setup with mixed precision in a PyTorch Distributed Data Parallel (DDP) environment, with a total of 169,680 iterations and a batch size of 384.
The learning rate varies per model. The Adam optimizer is used along with a 1-cycle learning rate scheduler. At iteration 127,260 (75% of the total), Stochastic Weight Averaging (SWA) is applied, replacing the 1-cycle scheduler with the SWA scheduler. Validation is performed every 1,000 steps, and the final checkpoint is selected based on the averaged weights.
- Model Configuration: For PARSeq, permutations are used. Both PARSeq and ViTSTR use an image patch size of 8×4.
- Label Preprocessing: Following prior research, the maximum label length is set to , and the charset size includes uppercase and lowercase letters, numbers, and punctuation marks.
- Image Preprocessing: Images are first augmented, resized, and then normalized to the range . Augmentation operations primarily consist of RandAugment (excluding Sharpness), with the addition of Invert to improve recognition of house number data, as well as GaussianBlur and PoissonNoise for STR data augmentation. The augmentation strategy uses 3 layers with a magnitude of 5. All images are resized to 128×32 pixels.
Discussion
Analysis of Training Permutations
The number of possible orders is , growing factorially with sequence length. Training on a sampled number of permutations controls the cost. The table shows how affects the accuracy of different decoding schemes: AR and NAR use no refinement, while the cloze column measures one refinement pass initialized with the ground-truth label.
-
Single Permutation Training ():
With , only the left-to-right order is used, simplifying training to standard autoregressive (AR) modeling. In this setup, non-autoregressive (NAR) decoding reaches only 0.01% accuracy, while AR decoding performs as expected. Refinement (or cloze) accuracy is only 71.14%, despite starting from the ground-truth label.
-
Multiple Permutation Training ():
When , all decoding schemes achieve satisfactory performance, indicating that PLM is indeed essential for a unified STR model. Intuitively, NAR decoding cannot function effectively with only one or two orders (forward and/or reverse, ) because the training context lacks sufficient variety. NAR decoding relies on prior knowledge for each character, which can only be adequately learned if all characters in the charset naturally appear as the first character in sequences.
-
Optimal Balance ():
Using achieves the best balance between decoding accuracy and training time. The high cloze accuracy of the internal language model (approximately 94%) demonstrates the advantage of combining image features with language context for prediction refinement. After all, the primary input signal in STR comes from the image rather than language context alone.
Comparison with Existing Methods
The authors compared PARSeq with well-known and recent SOTA methods and reproduced several models for a fair comparison. Most reproduced models achieved higher accuracy than originally reported. ABINet was an exception, with combined accuracy about 1.4 percentage points lower; its original setup used a longer training schedule (80 epochs of language-model pretraining and 8 of vision-model pretraining) and the additional WikiText-103 corpus.
In the table, PARSeqA uses AR initial decoding followed by one refinement pass, while PARSeqN uses NAR initial decoding followed by two refinement passes. Across the reproduced experiments with either synthetic or real training data, PARSeqA has the highest word accuracy and PARSeqN is usually second or third. Real-data training generally improves the reproduced models over synthetic-data training, and PARSeqA has the highest accuracy among those reproduced models.
The accuracy across different charset sizes is shown below:
The average accuracy for different charsets shows a sharp decline from 36 to 62 and 94 charset sizes when trained on synthetic data, suggesting a lack of diversity in uppercase and lowercase characters in synthetic datasets. PARSeqA consistently achieved the highest accuracy across all charset sizes.
Conclusion
By introducing the concept of PLM, PARSeq integrates the language model into the STR framework and enhances performance through multi-permutation training. This approach achieves SOTA results across key STR metrics and performs optimally across different charset sizes.
The appeal of language models is undeniable, and as we integrate the latest NLP techniques into other domains, we may find even more exciting breakthroughs.