SAFL: A Self-Attention Scene Text Recognizer with Focal Loss
- Publication
- ICMLA 2020Conference
- First submitted to arXiv
- arXiv:2201.00132
Cite this paper · BibTeX
The citation identifies the linked source version. It cites the original paper and its authors.
@misc{textrecognitionsafl2022,
title = {{SAFL: A Self-Attention Scene Text Recognizer with Focal Loss}},
author = {Bao Hieu Tran and Thanh Le-Cong and Huu Manh Nguyen and Duc Anh Le and Thanh Hung Nguyen and Phi Le Nguyen},
year = {2022},
eprint = {2201.00132},
archivePrefix = {arXiv},
url = {https://arxiv.org/abs/2201.00132}
}
Transformers are increasingly common in Scene Text Recognition (STR) research.
Research should have a little fun, too: this time, the authors tried Focal Loss to see whether it could improve the model.
Problem Definition
There are two commonly used methods for STR training.
CTC loss sums the probabilities of all alignments that collapse to the target string. Training requires the transcription, but no explicit correspondence between each feature position and each character.
The second method is CrossEntropy Loss. Models using this method typically require a decoder to align output and labels, often implemented with an LSTM or Transformer decoder.
Since we already have CrossEntropy Loss, exploring alternative loss functions is a natural next step. In object detection, Focal Loss has become popular, so why not give it a try here as well?
Thus, the authors proposed SAFL, an STR model that incorporates Focal Loss as the loss function.
Solution
Model Architecture
Original paper, Figure 1: rectification, feature extraction, and recognition.
The architecture here is straightforward, largely comprising components we’ve seen in previous work.
First comes a rectification network using a Thin Plate Spline (TPS) transformation. We covered this in:
Next, a CNN extracts features, and a Transformer encoder and decoder recognize the characters. We covered this setup in:
Finally, the authors replaced CrossEntropy Loss with Focal Loss.
Why make that replacement?
Why Focal Loss?
Original paper, Figure 2: character frequencies in the training lexicon. Frequency and prediction difficulty are different quantities.
The chart shows an uneven character distribution in the training lexicon: some characters appear often, others rarely. The authors suggest that this could favor easy, frequent examples at the expense of harder, less frequent ones. Focal Loss downweights easy predictions; prediction difficulty and character frequency are separate properties.
Focal Loss may help mitigate this issue. Its formula is as follows:
Here is the probability assigned to the correct character, while and are tunable parameters. As approaches 1, shrinks, so confident correct predictions contribute less to the update. This may help with less frequent examples, but it is not direct frequency-based weighting.
We previously explored this concept, which you can review here:
Discussion
Does Focal Loss Improve Performance?
Original paper, Table II: negative log-likelihood and Focal Loss for the same recognizer; the last row averages seven datasets.
In this table, the Focal Loss variant outperforms the negative log-likelihood (cross-entropy) variant on all seven datasets.
The table's mean accuracy rises from 86.9% to 88.2%, a 1.3 percentage-point difference. On CUTE it rises from 80.6% to 85.4%, a 4.8-point difference. The paper's prose says 2.3% for the mean, which conflicts with Table II; the calculation here follows the table. This ablation does not promise the same gain for every STR model.
Conclusion
In this study, the authors developed SAFL, a scene text recognition deep learning model that combines self-attention mechanisms with Focal Loss.
The experimental results show that SAFL achieves the highest average accuracy among the compared methods on the reported regular and irregular benchmarks.