Back to paper library
arXiv 2018ECCV 2018Text spottingPaper notes

Mask TextSpotter

Localization as Recognition

Original paper

Mask TextSpotter: An End-to-End Trainable Neural Network for Spotting Text with Arbitrary Shapes

Paper authors

Pengyuan Lyu · Minghui Liao · Cong Yao · Wenhao Wu · Xiang Bai

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}
}
On this page

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:

  1. ResNet-50 backbone with a Feature Pyramid Network (FPN).
  2. Region Proposal Network (RPN) to generate text proposals.
  3. Fast R-CNN for bounding box regression.
  4. 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:

  • 322,642,1282,2562,512232^2, 64^2, 128^2, 256^2, 512^2 pixels, corresponding to the five stages {P2,P3,P4,P5,P6}\{P_2, P_3, P_4, P_5, P_6\}.

Each stage uses three aspect ratios {0.5,1,2}\{0.5, 1, 2\} 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 7×77 \times 7.

Mask Branch

The mask branch performs two tasks: text instance segmentation and character segmentation.

Each RoI (fixed at 16×6416 \times 64) is processed by four convolutional layers and one deconvolutional layer. The mask branch generates 38 output maps of size 32×12832 \times 128, 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 PP and CC (if available), two types of mask maps are generated:

    1. Global Map: For text region localization.
    2. 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:

L=Lrpn+α1Lrcnn+α2LmaskL = L_{\text{rpn}} + \alpha_1 L_{\text{rcnn}} + \alpha_2 L_{\text{mask}}
  • LrpnL_{\text{rpn}} and LrcnnL_{\text{rcnn}} are the RPN and Fast R-CNN loss functions, respectively.

  • LmaskL_{\text{mask}} is the mask branch loss, including:

    • Global instance segmentation loss: LglobalL_{\text{global}}
    • Character segmentation loss: LcharL_{\text{char}}
    Lmask=Lglobal+βLcharL_{\text{mask}} = L_{\text{global}} + \beta L_{\text{char}}

The hyperparameters α1,α2,β\alpha_1, \alpha_2, \beta are experimentally set to 1.0.

  • Global Segmentation Loss

    With NN pixels in the mask map, yn∈{0,1}y_n \in \{0, 1\} as pixel labels, and xnx_n as model output, the loss is:

    Lglobal=−1N∑n=1N[yn⋅log⁡(S(xn))+(1−yn)⋅log⁡(1−S(xn))]L_{\text{global}} = -\frac{1}{N} \sum_{n=1}^{N} \left[ y_n \cdot \log(S(x_n)) + (1 - y_n) \cdot \log(1 - S(x_n)) \right]

    where S(x)S(x) 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 XX as an N×TN \times T matrix, where NN is the number of pixels per map and TT is the number of classes, the weighted spatial soft-max loss is:

    Lchar=−1N∑n=1NWn∑t=0T−1Yn,tlog⁡(eXn,t∑k=0T−1eXn,k)L_{\text{char}} = -\frac{1}{N} \sum_{n=1}^{N} W_n \sum_{t=0}^{T-1} Y_{n,t} \log\left( \frac{e^{X_{n,t}}}{\sum_{k=0}^{T-1} e^{X_{n,k}}} \right)

    where YY is the ground truth label, and WW is a weight balancing the loss between positive samples and the background class.

    If NnegN_{\text{neg}} is the number of background pixels and class index 0 denotes the background, the weight WiW_i is defined as:

    Wi={1ifYi,0=1,NnegN−NnegotherwiseW_i = \begin{cases} 1 & \text{if} \quad Y_{i,0} = 1, \\ \frac{N_{\text{neg}}}{N - N_{\text{neg}}} & \text{otherwise} \end{cases}

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:

  1. Input Test Image: Obtain candidate boxes via Fast R-CNN.
  2. Remove Redundant Boxes: Apply Non-Maximum Suppression (NMS).
  3. Generate Mask Maps: Feed the retained boxes into the mask branch to generate global and character masks.
  4. Extract Text Contours: Predict polygons from global masks.
  5. Generate Character Sequence: Use pixel voting to extract character sequences.

Pixel Voting Algorithm

Pixel voting converts the predicted character masks into character sequences:

  1. Binarize Background Map: Threshold the background map, whose values range from 0 to 255, at 192 to separate character regions from the background.
  2. Connected Region Detection: Extract the connected character regions from the binarized map.
  3. Average Pixel Value Calculation: For each region, average the pixel values on each character map to obtain its class scores.
  4. Character Assignment: Assign the class with the highest average to each region.
  5. 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.