Back to paper library
arXiv 2018AAAI 2019Text recognitionPaper notes

SAR

2D Attention Mechanism

Original paper

Show, Attend and Read: A Simple and Strong Baseline for Irregular Text Recognition

Paper authors

Hui Li · Peng Wang · Chunhua Shen · Guyu Zhang

Publication
AAAI 2019Conference
First submitted to arXiv
arXiv:1811.00751
Cite this paper · BibTeX

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

@misc{textrecognitionsar2018,
  title = {{Show, Attend and Read: A Simple and Strong Baseline for Irregular Text Recognition}},
  author = {Hui Li and Peng Wang and Chunhua Shen and Guyu Zhang},
  year = {2018},
  eprint = {1811.00751},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1811.00751}
}
On this page

Recognizing heavily distorted or curved text is a significant challenge for text recognition models. Although some previous approaches have tried to address this issue, such as using spatial transformation networks (STN) for geometric correction, these methods have had limited success.

Problem Definition

When tackling irregular text recognition, we can categorize previous approaches into three main directions:

  1. Correction Algorithms: A representative method in this category is RARE, which uses STN to apply geometric corrections. However, severely distorted text remains difficult to handle.

  2. Attention Mechanisms: These methods allow the model to focus on localized 2D features while decoding the text. The prior method cited here requires character-level supervision during training, making the training data more restrictive.

  3. Multi-Directional Encoding: This approach encodes text from four different orientations to handle arbitrarily oriented text. However, it requires a more complex architecture.


The authors prefer a simpler method.

Returning to an attention-based encoder-decoder framework, they propose a model based on ResNet and LSTM, combined with a custom 2D attention module to tackle irregular text recognition.

The attention module is trained with word-level text labels alone; it needs no extra character boxes or pixel-level annotations.

Solution

Model Architecture

Paper Figure 2; source: arXiv:1811.00751v2

As shown in the architecture diagram, the authors use ResNet-31 as the feature extractor. The resulting 2D feature map is retained for the decoder's attention. One max-pooling layer uses a 1×2 window, preserving more information along the horizontal axis.

Encoder

Paper Figure 3; source: arXiv:1811.00751v2

Once the feature map is obtained, the model uses an LSTM to encode the image.

We know that LSTM is designed for processing one-dimensional sequential data, so here, the authors apply max pooling along the "height" of the feature map to compress it into a one-dimensional sequence, which is then fed into the LSTM.

The LSTM consists of two layers, each with 512 hidden units, and from the diagram, it appears to be a unidirectional LSTM.

Decoder

Paper Figure 4; source: arXiv:1811.00751v2

The decoder also uses an LSTM.

As shown in the diagram, the main contribution of the authors is this: if you remove the "2D convolution feature map V" part, it becomes a basic LSTM decoder.

The decoder first receives the encoder's final hidden state. At each decoding step, it uses its current hidden state to compute attention weights over the original 2D convolutional feature map and select the local features it needs.

The LSTM in the decoder also has two layers with 512 hidden units each. The parameters between the encoder and decoder are not shared. During training, teacher forcing is used, but during inference, the model relies on the predictions from the previous timestep.

2D Attention Mechanism

Paper Figure 5; source: arXiv:1811.00751v2

To compensate for the limitations of traditional 2D attention mechanisms, the authors propose a novel attention mechanism that takes into account the spatial relationships in 2D space:

For each position (i,j)(i, j), the attention score incorporates information from neighboring positions. These neighboring positions are from the 8-connected neighborhood of (i,j)(i, j).

The attention score eije_{ij} is calculated using the following formula:

eij=tanh⁡(Wvvij+∑p,q∈NijW~p−i,q−j⋅vpq+Whht′)e_{ij} = \tanh(W_v v_{ij} + \sum_{p,q \in N_{ij}} \tilde{W}_{p-i, q-j} \cdot v_{pq} + W_h h'_t)

Where:

  • vijv_{ij} is the local feature vector at position (i,j)(i, j).
  • NijN_{ij} represents the 8-connected neighborhood around position (i,j)(i, j).
  • ht′h'_t is the hidden state of the decoder LSTM at time step tt, which serves as the attention guide.
  • Wv,WhW_v, W_h, and W~\tilde{W} are learnable weight matrices.

The attention weights αij\alpha_{ij} are computed using the softmax function:

αij=softmax(weT⋅eij)\alpha_{ij} = \text{softmax}(w_e^T \cdot e_{ij})

The attention-weighted sum (glimpse) gtg_t at time step tt is computed as:

gt=∑i,jαijvij,i=1,…,H,j=1,…,Wg_t = \sum_{i,j} \alpha_{ij} v_{ij}, \quad i = 1, \ldots, H, \quad j = 1, \ldots, W

Where HH and WW are the height and width of the feature map, respectively.

Compared to traditional attention mechanisms, this approach adds a weighted sum term for the 8-connected neighborhood, allowing the model to capture spatial relationships between local features.

Discussion

Comparison with Other Methods

Paper Table 2; source: arXiv:1811.00751v2

Across the irregular-text datasets in the table (IC15, SVTP, CT80, and COCO-T), SAR has the highest accuracy in every listed setting. The following examples use the no-lexicon columns:

  • On SVTP-None, SAR's 86.4% exceeds the 78.9% of Liu, Chen, and Wong (2018) by 7.5 percentage points; the asterisk on that comparator denotes extra character annotations.
  • On CT80-None, SAR's 89.6% exceeds the 79.5% of Shi et al. (2018) by 10.1 percentage points.

SAR is also competitive on regular text datasets such as IIIT5K, SVT, and IC13: its no-lexicon IIIT5K score is 95.0%, while its 91.2% on SVT and 94.0% on IC13 are not the highest in the table.

Without a lexicon, SAR has the highest listed scores on IIIT5K and SVTP, at 95.0% and 86.4%. Methods marked with an asterisk also use character-level annotations, which matters when comparing their training data.

Visualization

Paper Figure 7; source: arXiv:1811.00751v2

The authors compare the SAR 2D attention model with a traditional 2D attention model.

The decoded characters appear to the left of their attention maps, with incorrect characters marked in red. In the two examples shown, SAR's attention locations and recognition results are more accurate than those of traditional 2D attention.

Conclusion

SAR shows strong performance on both regular and irregular text recognition tasks. It also leaves room for further work, especially on speeding up training and handling more complex text structures.

Several later studies use SAR as a baseline for comparison, which we'll explore in future discussions.