Back to paper library
arXiv 2021CVPR 2021Text recognitionPaper notes

ABINet

Thinking more!

Original paper

Read Like Humans: Autonomous, Bidirectional and Iterative Language Modeling for Scene Text Recognition

Paper authors

Shancheng Fang · Hongtao Xie · Yuxin Wang · Zhendong Mao · Yongdong Zhang

Publication
CVPR 2021Conference
First submitted to arXiv
arXiv:2103.06495
Cite this paper · BibTeX

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

@misc{textrecognitionabinet2021,
  title = {{Read Like Humans: Autonomous, Bidirectional and Iterative Language Modeling for Scene Text Recognition}},
  author = {Shancheng Fang and Hongtao Xie and Yuxin Wang and Zhendong Mao and Yongdong Zhang},
  year = {2021},
  eprint = {2103.06495},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2103.06495}
}
On this page

Visual recognition seems to have reached its limit. People began thinking about how to make a model understand and read text more like a person.

Problem Definition

Previous research has often relied solely on visual features for text recognition. However, when text is blurred, occluded, or distorted, models struggle to recognize it accurately. This is because visual features are compromised, making it difficult for the model to detect text reliably.

To address this limitation, researchers have begun incorporating language models to help models understand text contextually. For instance, if we see a blurred text like “APP?E,” a language model can help us infer that the intended word is likely “APPLE.”

Human reading behavior is generally characterized by:

  1. Autonomy: Humans can learn from both visual and linguistic cues independently, with language knowledge supporting visual understanding of text.
  2. Bidirectionality: When text is unclear, humans use surrounding context to fill in the blanks.
  3. Iterative Process: Humans can continuously refine their understanding through repeated reasoning and correction.

This paper’s authors propose that models should replicate these human reading characteristics:

  1. Autonomy: The model uses separate vision and language modules to model text independently by its visual and linguistic features.
  2. Bidirectionality: The authors introduce a “Bidirectional Cloze Network” that learns from context on both sides of the text.
  3. Iterative Process: The model refines its predictions iteratively, gradually improving its accuracy.

With this approach in mind, the authors have defined the conceptual foundation. The remaining step is to prove its effectiveness through experimentation!

Solution

The authors propose a new model architecture: ABINet, designed to tackle the challenges of scene text recognition.

Visual Model

The visual model follows a familiar architecture: it uses ResNet to extract features and a Transformer to model the sequence, transforming an input image xx into a feature representation:

Fb=τ(R(x))∈RH4×W4×CF_b = \tau(R(x)) \in \mathbb{R}^{\frac{H}{4} \times \frac{W}{4} \times C}

where HH and WW represent the image dimensions, and CC is the feature dimension.

Positional attention converts the spatial features FbF_b into per-position visual features FvF_v; a classification head then produces character probabilities:

Fv=softmax(QKTC)VF_v = \text{softmax}\left(\frac{QK^T}{\sqrt{C}}\right)V

Here's a breakdown of each component in the attention calculation:

  • Q∈RT×CQ \in \mathbb{R}^{T \times C}: This is the positional encoding of the character sequence, encoding each character's position in the sequence to help the model understand the order of characters. Specifically, TT represents the sequence length, or the number of characters to be processed, while CC denotes the feature dimension.

  • K=G(Fb)∈RHW16×CK = G(F_b) \in \mathbb{R}^{\frac{HW}{16} \times C}: The "key" KK is derived from FbF_b through a function G(⋅)G(\cdot), which in this case is implemented as a mini U-Net structure. The mini U-Net enriches spatial context. The number of keys remains HW/16HW/16, while the number of queries is TT; these need not be equal.

  • V=H(Fb)∈RHW16×CV = H(F_b) \in \mathbb{R}^{\frac{HW}{16} \times C}: The "value" VV is obtained by applying an identity mapping H(⋅)H(\cdot) on FbF_b, meaning that FbF_b is passed directly without additional transformations. This gives VV the same dimensions as KK, preserving consistency in feature space and spatial resolution.

The attention matrix has shape T×HW/16T \times HW/16. It weights the spatial features separately for each output position, producing Fv∈RT×CF_v \in \mathbb{R}^{T \times C}. These are feature vectors, not character probabilities.

Language Model

The language model in ABINet is integrated after the visual model, using several key strategies to improve text recognition performance:

  1. Autonomous Strategy:

    As shown in the diagram, the language model functions independently as a spelling correction model. It takes character probability vectors as input and outputs the probability distribution for each character. This independence allows the language model to be trained on unlabeled text data separately, enhancing the model's interpretability and modularity. Replacing the language model still requires a compatible character set, input/output representation, and training setup.

    To ensure this autonomy, the authors introduce a technique called Blocking Gradient Flow (BGF), which detaches the language model’s input probabilities: gradients from the language branch cannot flow back through those inputs into the visual prediction branch.

    This modular design allows linguistic pretraining to be studied separately, but does not make arbitrary pretrained language models drop-in replacements.

  2. Bidirectional Strategy:

    The language model calculates conditional probabilities for bidirectional and unidirectional representations, denoted as P(yi∣yn,…,yi+1,yi−1,…,y1)P(y_i | y_n, \dots, y_{i+1}, y_{i-1}, \dots, y_1) for bidirectional and P(yi∣yi−1,…,y1)P(y_i | y_{i-1}, \dots, y_1) for unidirectional. Bidirectional modeling provides richer semantic information by considering both left and right contexts.

    For a strict leave-one-position-out prediction, a straightforward use of a BERT-style masked language model would require separate masks for the target positions. BCN implements these cloze queries in parallel. This comparison concerns that use case; MLM training in general can mask multiple positions at once.

    BCN adopts a Transformer decoder-like structure but with unique modifications. Instead of causal masking, BCN uses a custom attention mask to prevent each character from "seeing" itself. At each layer, the keys and values come from the input character probabilities, while the queries use positional encodings or the previous layer's output; this also prevents information from leaking across layers.

    The mask matrix MM in BCN’s multi-head attention block is constructed as follows:

    Mij={0,i≠j−∞,i=jM_{ij} = \begin{cases} 0, & i \neq j \\ -\infty, & i = j \end{cases}

    Here, Ki=Vi=P(yi)WlK_i = V_i = P(y_i) W_l, where P(yi)∈RcP(y_i) \in \mathbb{R}^c is the probability distribution of character yiy_i, and Wl∈Rc×CW_l \in \mathbb{R}^{c \times C} is a linear mapping matrix.

    The multi-head attention computation is given by:

    Fmha=softmax(QKTC+M)VF_{\text{mha}} = \text{softmax}\left(\frac{QK^T}{\sqrt{C}} + M\right)V

    In this, Q∈RT×CQ \in \mathbb{R}^{T \times C} represents positional encodings in the first layer and outputs from the previous layer in subsequent layers, while KK and V∈RT×CV \in \mathbb{R}^{T \times C} come from the linear mapping of character probabilities P(yi)P(y_i).

    The BCN’s cloze-like attention mask enables the model to learn a stronger bidirectional representation, capturing more complete semantic context than unidirectional models.

  1. Iterative Strategy:

    The authors propose an Iterative Correction strategy to address noise in the visual model’s input, which can lower prediction confidence during Transformer’s parallel decoding. In the first iteration, yi1y_{i_1} represents the visual model's probability predictions. In subsequent iterations, yi≥2y_{i \geq 2} comes from the previous fusion model's predictions.

  1. Fusion

    Since the visual model is trained on image data and the language model on text data, these two sources of information need to be aligned. The authors employ a "gated mechanism" to fuse the visual and language features effectively, balancing their contributions in the final prediction.

    Visual features FvF_v and language features FlF_l are concatenated, and a linear mapping Wf∈R2C×CW_f \in \mathbb{R}^{2C \times C} compresses the concatenated features to match the dimensions of FvF_v and FlF_l.

    The gated vector GG is calculated as:

    G=σ([Fv,Fl]Wf)G = \sigma([F_v, F_l] W_f)

    Here, σ\sigma is the Sigmoid function, which bounds GG between 0 and 1, controlling the balance between the visual and language features in the final output.

    The fused feature FfF_f is obtained by weighted combining FvF_v and FlF_l as follows:

    Ff=G⊙Fv+(1−G)⊙FlF_f = G \odot F_v + (1 - G) \odot F_l

    where ⊙\odot represents element-wise multiplication. When GG is close to 1, visual features FvF_v have a stronger influence, while a value close to 0 gives more weight to language features FlF_l.

  2. Supervised Training

    ABINet is trained end-to-end with a multi-task objective, combining the losses from the visual, language, and fused features.

    The objective function is:

    L=λvLv+λlM∑i=1MLli+1M∑i=1MLfiL = \lambda_v L_v + \frac{\lambda_l}{M} \sum_{i=1}^{M} L_l^i + \frac{1}{M} \sum_{i=1}^{M} L_f^i

    where:

    • LvL_v: Cross-entropy loss for visual features FvF_v.
    • LlL_l: Cross-entropy loss for language features FlF_l.
    • LfL_f: Cross-entropy loss for fused features FfF_f.
    • LliL_l^i and LfiL_f^i: Losses at iteration ii for language and fused features, respectively.
    • λv\lambda_v and λl\lambda_l: Balancing factors for adjusting the contributions of each loss term, ensuring a balanced influence from visual and language features in training.

Implementation Details

  • Training Datasets: The model is trained on two synthetic datasets, MJSynth (MJ) and SynthText (ST).
  • Testing Datasets: The evaluation is conducted on six standard benchmark datasets: ICDAR 2013 (IC13), ICDAR 2015 (IC15), IIIT 5K-Words (IIIT), Street View Text (SVT), Street View Text-Perspective (SVTP), and CUTE80 (CUTE).
  • Unlabeled Data for Semi-supervised Learning: The Uber-Text dataset (with labels removed) is used to assess the effectiveness of semi-supervised learning.
  • Model Configuration: The model dimension CC is set to 512, with the Bidirectional Cloze Network (BCN) comprising 4 layers and 8 attention heads per layer. The balancing factors λv\lambda_v and λl\lambda_l are both set to 1.
  • Image Preprocessing: Images are resized to 32×128 and augmented with techniques such as geometric transformations, image quality degradation, and color jittering to improve robustness.
  • Training Environment: The training is conducted on four NVIDIA 1080Ti GPUs with a batch size of 384. The ADAM optimizer is used with an initial learning rate of 1×10−41 \times 10^{-4}, which decays to 1×10−51 \times 10^{-5} after the sixth epoch.

Discussion

Comparison with Other Methods

To ensure a fair and rigorous comparison, the authors re-implemented the SOTA algorithm SRN using the same experimental configuration as ABINet. Two re-implemented versions of SRN were tested with different visual models (VMs), alongside several adjustments, such as replacing the VM, removing the side effects of multi-scale training, and applying learning rate decay. These modifications resulted in improved performance compared to the original SRN as reported.

  • Comparison between ABINet-SV and SRN-SV: ABINet-SV outperformed SRN-SV across multiple datasets.
  • Performance of ABINet-LV: With a stronger VM, ABINet-LV outperformed the corresponding SRN-LV on five of the six datasets; IIIT is the exception, at 96.2% versus 96.3%.

ABINet trained on MJ and ST performed particularly well on challenging datasets like SVT, SVTP, and IC15, which contain numerous low-quality images with noise and blur. ABINet leveraged linguistic information to significantly enhance recognition accuracy, especially under these difficult conditions.

Furthermore, ABINet was able to recognize irregular fonts and non-standard layouts effectively, thanks to the complementary role of language information in visual feature processing. Even without image rectification, ABINet achieved second-best performance on the CUTE dataset, showing its robust ability to handle irregular text.

Ablation Study - Visual Model

In this ablation study, the authors mainly compared different feature extraction and sequence modeling methods.

The proposed "positional attention" technique demonstrated a stronger capacity for representing key-value vectors compared to common parallel attention methods.

Additionally, upgrading the visual model (VM) significantly improved accuracy, albeit at the cost of additional parameters and computational overhead. Alternatively, performance can be enhanced by using positional attention for feature extraction and employing a deeper Transformer for sequence modeling in the VM.

Ablation Study - Language Model

  • PVM: Indicates supervised pre-training of the visual model (VM) on the MJ and ST datasets.
  • PLMin\text{PLM}_{in}: Refers to self-supervised pre-training of the language model (LM) on the MJ and ST datasets.
  • PLMout\text{PLM}_{out}: Refers to self-supervised pre-training of the language model on the large-scale WikiText-103 dataset.
  • AGF (Allowing Gradient Flow): This setting allows gradient flow between the visual model and the language model.

Findings:

  • PVM: Supervised pre-training of the VM (PVM) results in an average accuracy improvement of 0.6–0.7 percentage points, showing that pre-training the visual model significantly enhances its text recognition performance.

  • PLMin\text{PLM}_{in}: The effect of PLMin\text{PLM}_{in} is limited, likely because the MJ and ST datasets lack the diversity and language structure needed to provide comprehensive linguistic information.

  • PLMout\text{PLM}_{out}: Pre-training the LM on the larger and more diverse WikiText-103 dataset (PLMout\text{PLM}_{out}) leads to a significant improvement, as this dataset enriches the LM's understanding of textual context, enhancing performance even when accuracy is already high.

  • AGF: Allowing gradients through the language model’s input probabilities lowers mean accuracy from 92.3% to 91.4%, a drop of 0.9 percentage points, while training loss falls quickly. The authors interpret this as possible overfitting: the language model may use information from the visual model to "cheat" during training. BGF blocks this backward path and supports more independent language modeling.

Ablation Study - Bidirectional Strategy

Since BCN is a Transformer-based variant, it was compared to SRN, another Transformer-based model.

To ensure fairness, the experiments were conducted under identical conditions except for network structure. SV and LV were used as visual models (VMs) to evaluate BCN's effectiveness at different accuracy levels.

  • BCN vs. SRN-U: BCN, when compared to SRN's unidirectional version (SRN-U), has similar parameters and inference speed but demonstrates a competitive advantage in accuracy across different VMs.

  • BCN vs. Bidirectional SRN: BCN outperforms the bidirectional SRN, especially on challenging datasets like IC15 and CUTE. In the table, inference time falls from 24.2 to 19.5 ms with SV and from 26.9 to 22.0 ms with LV; accuracy for each configuration should be compared alongside speed.

Visualization Analysis

To understand how BCN operates within ABINet, the authors visualized the top-5 prediction probabilities for the word "today," as shown in the figure above.

  • When the input is “-oday” or “tod-y,” BCN confidently predicts “t” and “a,” contributing positively to the final fusion predictions.
  • For erroneous characters like “l” and “o,” BCN’s confidence is low, minimizing their impact on the final prediction.
  • When multiple erroneous characters are present, BCN struggles to restore the correct text due to insufficient contextual support.

This visualization demonstrates BCN’s ability to leverage context for accurate predictions and highlights its limitations when handling extensive errors in the input text.

Conclusion

This paper introduces a language model branch into text recognition models. Through the autonomous, bidirectional, and iterative design, ABINet effectively improves text recognition accuracy and generalization. Experimental results demonstrate that ABINet achieves outstanding performance across multiple benchmark datasets, particularly excelling in irregular text and low-quality images.