Mask TextSpotter: An End-to-End Trainable Neural Network for Spotting Text with Arbitrary Shapes
- Publication
- ECCV 2018Conference
- First submitted to arXiv
- arXiv:1807.02242
Cite this paper · BibTeX
The citation identifies the linked source version. It cites the original paper and its authors.
@misc{textspottingmasktextspotter2018,
title = {{Mask TextSpotter: An End-to-End Trainable Neural Network for Spotting Text with Arbitrary Shapes}},
author = {Pengyuan Lyu and Minghui Liao and Cong Yao and Wenhao Wu and Xiang Bai},
year = {2018},
eprint = {1807.02242},
archivePrefix = {arXiv},
url = {https://arxiv.org/abs/1807.02242}
}
When I first saw this paper, both the model design and the way the figures were drawn felt strangely familiar. I went back to check the authors: several also worked on CA-FCN at Megvii (Face++).
Returning to this paper, the authors were inspired by Mask R-CNN. Using pixel-level prediction, they locate text and classify its characters.
To pay homage to Mask R-CNN, the authors named their model Mask TextSpotter.
Problem Definition
In real-world scenarios, text can take on many shapes: horizontal, vertical, curved, slanted...
All kinds of shapes you can and cannot imagine.
Text detection methods are usually inspired by object detection designs, but these approaches struggle with adapting to variable text shapes, leading to poor performance.
At the time, CTC-based recognition was popular. Those systems often reduced the image to a one-dimensional feature sequence, making curved text difficult without rectification or a suitable feature extractor; CTC itself does not require horizontal text.
Is it possible to find a method that can detect text locations and recognize text simultaneously?
We want the best of both worlds!
Solution
Model Architecture
The model architecture is illustrated briefly above. Let’s follow the paper to understand it in more detail.
This architecture consists of four main parts, as shown in the figure:
- ResNet-50 backbone with a Feature Pyramid Network (FPN).
- Region Proposal Network (RPN) to generate text proposals.
- Fast R-CNN for bounding box regression.
- Mask Branch for text instance segmentation and character segmentation.
Backbone & Neck
To establish high-level semantic feature maps across different scales, the authors employed ResNet-50 as the backbone, combined with an FPN structure. The FPN merges features from different resolutions top-down, improving accuracy with minimal additional computational cost.
Region Proposal Network (RPN)
The Region Proposal Network (RPN) generates text proposals for both the Fast R-CNN and mask branches.
At each stage, different-sized anchors are used, with areas of:
- pixels, corresponding to the five stages .
Each stage uses three aspect ratios for training.
The RoI Align method is used for region feature extraction, which better preserves spatial information compared to RoI Pooling, aiding in segmentation tasks.
Fast R-CNN Branch
During training, RPN generates many text proposals, which are fed into the Fast R-CNN branch and the mask branch.
The Fast R-CNN branch handles:
- Classification: Classifying proposals as text or non-text.
- Regression: Adjusting the bounding boxes of text proposals.
This branch refines the bounding boxes proposed by RPN, using RoI features aligned to a resolution of .
Mask Branch
The mask branch performs two tasks: text instance segmentation and character segmentation.
Each RoI (fixed at ) is processed by four convolutional layers and one deconvolutional layer. The mask branch generates 38 output maps of size , including:
- Global word map: Localizing text regions.
- 36 character maps: Corresponding to 26 letters and 10 digits.
- Background map: Marking non-character regions for post-processing.
Label Generation
-
RPN and Fast R-CNN Target Generation
The polygon annotations are converted into minimum horizontal rectangles that enclose them. Then, targets for RPN and Fast R-CNN are generated following the target-assignment procedures of Fast R-CNN, Faster R-CNN, and FPN.
-
Mask Branch Label Generation
For each positive RPN proposal, the matching procedure first finds its annotated horizontal rectangle. The corresponding polygon and character boxes (if available) are then transformed into the proposal's fixed mask coordinates. Using the annotations and (if available), two types of mask maps are generated:
- Global Map: For text region localization.
- Character Map: For labeling character classes.
-
Global Map Generation
A polygon is drawn on an initially blank mask map (all 0s), filling the interior with 1s.
-
Character Map Generation
As shown above, the center of the character box is fixed, and each side is shortened to one-fourth of its original length. Pixels inside the shrunken box are assigned the character’s class index, while those outside are set to 0. If no character box is annotated, all pixels are set to -1.
Loss Function
Since the architecture contains several branches, the authors employ a multi-task loss function for optimization:
-
and are the RPN and Fast R-CNN loss functions, respectively.
-
is the mask branch loss, including:
- Global instance segmentation loss:
- Character segmentation loss:
The hyperparameters are experimentally set to 1.0.
-
Global Segmentation Loss
With pixels in the mask map, as pixel labels, and as model output, the loss is:
where is the sigmoid function mapping outputs to probabilities between 0 and 1.
-
Character Segmentation Loss
The character segmentation output consists of 37 mask maps (36 for characters and one for the background). Treating the output maps as an matrix, where is the number of pixels per map and is the number of classes, the weighted spatial soft-max loss is:
where is the ground truth label, and is a weight balancing the loss between positive samples and the background class.
If is the number of background pixels and class index 0 denotes the background, the weight is defined as:
Inference Phase
During inference, sigmoid produces the global mask and soft-max produces the character maps. The mask branch uses the more accurate outputs of Fast R-CNN as its proposals instead of taking proposals directly from RPN. The steps are as follows:
- Input Test Image: Obtain candidate boxes via Fast R-CNN.
- Remove Redundant Boxes: Apply Non-Maximum Suppression (NMS).
- Generate Mask Maps: Feed the retained boxes into the mask branch to generate global and character masks.
- Extract Text Contours: Predict polygons from global masks.
- Generate Character Sequence: Use pixel voting to extract character sequences.
Pixel Voting Algorithm
Pixel voting converts the predicted character masks into character sequences:
- Binarize Background Map: Threshold the background map, whose values range from 0 to 255, at 192 to separate character regions from the background.
- Connected Region Detection: Extract the connected character regions from the binarized map.
- Average Pixel Value Calculation: For each region, average the pixel values on each character map to obtain its class scores.
- Character Assignment: Assign the class with the highest average to each region.
- Character Sorting: Sort characters from left to right, following English reading order. This rule has limitations for vertical text or curves whose reading order is not monotonic along the horizontal axis.
When a lexicon is provided for evaluation, the authors also use the character probabilities from pixel voting to compute a weighted edit distance and select a matching word from the lexicon.
Discussion
Horizontal Text Recognition
The authors evaluated the model's performance on horizontal text detection and recognition using the ICDAR2013 dataset. During testing, all input images were resized so that their shorter side measured 1000 pixels, and the model was evaluated online.
The results show that even with single-scale evaluation, the model achieved a detection F-Measure of 91.7%, outperforming some previous methods that used multi-scale evaluation. For word spotting, it performed comparably to the previous best method. In end-to-end recognition, its scores exceed Li et al. by 1.1 to 1.9 percentage points across the three lexicon settings in the table.
Skewed Text Recognition
The authors also evaluated the model on the ICDAR2015 dataset to test its effectiveness in detecting and recognizing skewed text. Since ICDAR2015 contains a large amount of small-sized text, the authors tested the model on three different input scales:
- Original resolution: 720 × 1280
- Two enlarged resolutions: Inputs resized so that the shorter side measures 1000 and 1600 pixels
At the original resolution, the model achieved a detection F-Measure of 84%, 3.0 percentage points above the best previous method evaluated at multiple scales. With the shorter side enlarged to 1000, its F-Measure reached 86.0%, at least 5.0 percentage points above the other methods in the table.
For word spotting and end-to-end recognition with the shorter side enlarged to 1600, the scores exceed Deep Text Spotter by 13.2 to 25.3 percentage points across the table's lexicon settings.
Curved Text Recognition
To assess robustness on curved text, the authors used Total-Text and resized the test images to a shorter side of 1000 pixels. The evaluation follows the ICDAR2015 protocol but allows polygons with any number of vertices instead of quadrilaterals to represent curved text regions.
Compared with TextBoxes in the table, Mask TextSpotter raises the detection F-Measure by 8.8 percentage points. In end-to-end recognition, the gains are 16.6 percentage points without a lexicon and 22.9 percentage points with the full lexicon.
The following figure illustrates the differences in stability between TextBoxes (top row) and Mask TextSpotter (bottom row):
Visualization
Conclusion
Mask TextSpotter handles horizontal text (ICDAR2013), oriented text (ICDAR2015), and curved text (Total-Text) well. For irregular text shapes, it addresses a limitation of traditional recognition methods.
Its jointly trainable design simplifies training and performs well on detection, lexicon-based word spotting, and end-to-end recognition. That gives later research and practical applications a useful point of reference.