Mask R-CNN
- Publication
- ICCV 2017Conference
- First submitted to arXiv
- arXiv:1703.06870
Cite this paper · BibTeX
The citation identifies the linked source version. It cites the original paper and its authors.
@misc{segmentationmaskrcnn2017,
title = {{Mask R-CNN}},
author = {Kaiming He and Georgia Gkioxari and Piotr Dollár and Ross Girshick},
year = {2017},
eprint = {1703.06870},
archivePrefix = {arXiv},
url = {https://arxiv.org/abs/1703.06870}
}
Semantic segmentation labels every pixel with a class. If five people stand in a street scene, semantic segmentation paints all five the same color and tells you "these pixels are person," but it can't say which pixels belong to which person.
Instance segmentation asks for the latter. It has to find each object first and then draw an outline for each one, which amounts to doing detection and segmentation together.
In March 2017, Kaiming He, Georgia Gkioxari, Piotr Dollár and Ross Girshick of FAIR published Mask R-CNN. Kaiming He of ResNet, Ross Girshick of the R-CNN series and Piotr Dollár are all also authors of FPN. The paper's approach is very much in their style, adding one branch to Faster R-CNN and then fixing a detail that looks tiny.
Defining the Problem
Instance segmentation methods at the time fell roughly into two camps.
The first camp segments first, then recognizes. Methods like DeepMask generate a pile of candidate segments and then hand them to Fast R-CNN for classification; MNC uses a multi-stage cascade that generates segments from boxes and then classifies them. Segmentation comes before recognition, which is slow and not very accurate.
The second camp starts from semantic segmentation, first classifying every pixel with an FCN and then working out how to split pixels of the same class into separate individuals.
Its latest representative is FCIS, winner of the 2016 COCO segmentation challenge. It uses a set of position-sensitive output channels to handle classes, boxes and masks at once, and it is fast. But the authors point out that FCIS makes systematic errors and produces spurious edges where objects overlap, as we'll see in the experiments shortly.
Meanwhile, detection already had Faster R-CNN and semantic segmentation had FCN, both simple, easy to modify and fast to train. The authors set out to find an equally handy baseline for instance segmentation.
Solving the Problem
A Quick Review of Faster R-CNN
This site doesn't have a Faster R-CNN note yet, so let's cover it in a few sentences.
Faster R-CNN is a two-stage detector. The first stage is the Region Proposal Network (RPN), which slides over the backbone's feature map, judges for a set of preset anchor boxes whether there is an object there, and outputs candidate boxes. The second stage cuts a fixed-size feature, say , out of the feature map for each candidate box (RoI, Region of Interest), then classifies it with fully connected layers and refines the box position.
The step that cuts the fixed-size feature out of the feature map is called RoIPool. However large or small the candidate box, the extracted features are the same size, so the classifier after it can take them.
Adding a Third Branch

Mask R-CNN's first stage is exactly the same as Faster R-CNN's. The second stage originally had two outputs, classification and box regression; now a mask branch is added, and the three are computed in parallel.
This "in parallel" is deliberate. In DeepMask, MNC, FCIS and similar methods, classification depends on the mask results; Mask R-CNN lets the mask and the classification each do their own job, just as Fast R-CNN once made classification and box regression parallel and simplified away R-CNN's multi-stage pipeline.
During training, the loss for each RoI is
The first two terms come straight from Fast R-CNN. The mask branch outputs masks of for each RoI, where is the number of classes, one mask per class. Each pixel goes through a sigmoid and binary cross-entropy is computed; if the RoI's ground-truth class is , the loss is computed only on the -th mask, and the other are ignored.
This differs from FCN's habit in semantic segmentation. FCN applies a -class softmax at each pixel, with the classes competing, so a pixel that is a person can't be a car. Each Mask R-CNN mask answers a single yes-or-no question, "If this object is , does this pixel belong to it?" Which class the object actually is gets left to the classification branch.
Masks Must Keep Their Spatial Layout
Class and box offsets are just a few numbers, and squeezing them into a vector with fully connected layers is fine. A mask is different; it is an image in its own right.
So the mask branch uses an FCN, convolving from the RoI features all the way to the output and keeping the spatial structure at every layer. DeepMask and other methods predict masks with fully connected layers; the authors will show in the experiments that the convolutional version has fewer parameters and is more accurate.
The convolutional version, however, requires every position on the RoI features to correspond accurately to a position in the original image. RoIPool can't deliver that.
What's Wrong with RoIPool
Let's work through an example. The backbone's stride is 16, and a candidate box spans 10 to 165 pixels in on the original image, 155 pixels wide.
Converted to the feature map, the left and right edges are and . RoIPool's first step rounds them to the integer grid points 1 and 10, which map back to roughly 16 to 176 pixels in the original image. The left edge moves 6 pixels to the right, and the right edge reaches 11 pixels further out.
The second step splits these 10 cells into 7 bins of 1.43 cells each, which again has to be rounded, so some bins get 1 cell and some get 2. Max pooling is then done inside each bin.
For classification this bit of offset is harmless; an object shifted by a few pixels is still the same object. But in the stride-16 C4 architecture, the mask branch outputs only , so for this box each mask pixel corresponds to about 11 pixels of the original image; the 6-pixel shift in the left edge puts the mask off by more than half a cell, and the 11 extra pixels on the right are a whole cell.
RoIAlign
The fix is direct. Don't round anywhere.

RoIAlign takes the floating-point range from to as is and divides it evenly into 7 bins, each cells wide. Each bin gets 4 regularly placed sampling points (); the sampling points mostly fall between grid points, and each one's value is bilinearly interpolated from the four surrounding grid points. The average or maximum of the 4 points is the bin's output.
In the figure, the solid box doesn't line up with the dashed grid and the sampling points aren't on grid points, and that is exactly the point. The authors specifically note that the results are not very sensitive to where the sampling points go or how many there are, as long as nothing is quantized.
MNC's RoIWarp also uses bilinear interpolation, but it quantizes the RoI before that. As the experiments will show, RoIWarp scores about the same as RoIPool; the problem lies in alignment, not interpolation.
Two Kinds of Head

The authors treat the backbone (features for the whole image) and the head (the work done for each RoI) separately, and experiment with two combinations.
ResNet-C4: the backbone uses ResNet only up to the fourth stage, and the fifth stage (res5) moves into the head, where it runs once for every RoI. This is how Faster R-CNN originally used ResNet, and it is computationally heavy.
FPN: res5 is already in the backbone, each RoI takes features from a pyramid level chosen by its size, and the head is much lighter. The mask branch starts from RoI features, applies four convolutions and one , stride-2 deconvolution up to , and finally a convolution outputs one mask for each of the 80 (COCO) classes.
The authors say both mask branches are deliberately kept simple; more elaborate designs might do better, but they aren't the focus of this paper.
Training and Inference
The hyperparameters are mostly carried over from Faster R-CNN and FPN. An RoI with IoU of at least 0.5 against a ground-truth box is positive, and the mask loss is computed only on positives; the mask target is the intersection of the RoI and the ground-truth mask. Images are resized so the short side is 800, and training runs on 8 GPUs with 2 images each for 160k iterations, at a learning rate of 0.02 divided by 10 at iteration 120k.
Inference differs somewhat from training. In training, the three branches run in parallel on all RoIs; at inference, the box branch and NMS run first, and only the 100 highest-scoring boxes go through the mask branch. The mask for the predicted class is taken, its probability map is resized to the box size and binarized at a threshold of 0.5.
Because only 100 boxes are processed, the mask branch adds about 20% to Faster R-CNN's running time. ResNet-101-FPN takes 195 ms per image on a Tesla M40, plus 15 ms of CPU time to resize the outputs back to the original image.
Discussion
All experiments are on COCO. The training set is 80k train images plus 35k val images (trainval35k), ablations are evaluated on the remaining 5k (minival), and the main results are submitted to test-dev. AP is averaged over IoU 0.5 to 0.95, AP50 and AP75 use fixed thresholds, and unless stated otherwise IoU is computed on masks.
Main Results
Table 1 of the paper, mask AP on COCO test-dev:
| Method | Backbone | AP | AP50 | AP75 |
|---|---|---|---|---|
| MNC (2015 winner) | ResNet-101-C4 | 24.6 | 44.3 | 24.8 |
| FCIS+OHEM (2016 winner) | ResNet-101-C5-dilated | 29.2 | 49.5 | – |
| FCIS+++ +OHEM | ResNet-101-C5-dilated | 33.6 | 54.5 | – |
| Mask R-CNN | ResNet-101-C4 | 33.1 | 54.9 | 34.8 |
| Mask R-CNN | ResNet-101-FPN | 35.7 | 58.0 | 37.8 |
| Mask R-CNN | ResNeXt-101-FPN | 37.1 | 60.0 | 39.4 |
FCIS+++ used multi-scale training and testing, horizontal-flip testing and OHEM. Mask R-CNN adds none of these, and its ResNet-101-FPN version still wins by 2.1 points.

Look at the four people with umbrellas in the first column; where two neighbors meet, FCIS draws a boundary that belongs to neither of them. In the two trains at the far right, FCIS's colors run together at the junction. Mask R-CNN finds boxes first and then draws a mask inside each box, so neighboring individuals come out separate by construction.
Ablations
Table 2 of the paper breaks things down into five groups, all mask AP on minival:
- Backbone: ResNet-50-C4 30.3, ResNet-101-C4 32.7, ResNet-50-FPN 33.6, ResNet-101-FPN 35.4, ResNeXt-101-FPN 36.7. Depth, FPN and ResNeXt all help.
- Softmax or sigmoid: with the same ResNet-50-C4, a per-pixel softmax gets only 24.8, while an independent sigmoid per class gets 30.3, a 5.5-point gap. The authors' reading is that the classification branch has already judged the object as a whole, so the mask only needs to separate foreground from background, without competing against other classes again.
- One mask per class or one shared: a class-agnostic mask that outputs just one map gets AP 29.7, barely different from 30.3 with one per class. This further shows that classification and segmentation are already decoupled in Mask R-CNN.
- FCN or MLP: on ResNet-50-FPN, both fully connected mask branches get 31.5, and the four-layer convolutional FCN gets 33.6.
- RoIAlign: see the next section.
What Alignment Is Actually Worth
Comparison on ResNet-50-C4 (stride 16):
| RoI op | Align | Bilinear | AP | AP50 | AP75 |
|---|---|---|---|---|---|
| RoIPool | 26.9 | 48.8 | 26.4 | ||
| RoIWarp | ✓ | 27.2 | 49.2 | 27.1 | |
| RoIAlign | ✓ | ✓ | 30.3 | 51.2 | 31.5 |
RoIAlign adds 3.4 points, most of it at AP75, the threshold that demands tightly fitting masks. RoIWarp adds interpolation without alignment and barely improves.
The larger the stride, the worse the misalignment. Switching to ResNet-50-C5 with stride 32, RoIPool drops to 23.6 while RoIAlign gets 30.9, a 7.3-point gap, and the gap at AP75 is 10.5. Stride 32 with RoIAlign at 30.9 even beats stride 16 with RoIAlign at 30.3. The authors consider RoIAlign to have largely solved the long-standing problem that "large-stride features can't be used for precise localization."
Even on FPN, whose features are already fine, RoIAlign still adds 1.5 points of mask AP.
Detection Got Better Too
Drop the mask output and look only at boxes (Table 3 of the paper, box AP on test-dev), and Faster R-CNN with FPN on the same backbone gets 36.2, while Mask R-CNN gets 38.2.
The authors break these 2 points down. Switching to RoIAlign gives 37.3, a gain of 1.1; the remaining 0.9 comes from multi-task training, where learning masks during training makes the boxes more accurate too. Switching to ResNeXt-101 adds another 1.6, reaching 39.8.
Switching to Human Keypoints
Finally, the authors show how general the framework is. Each human keypoint (left shoulder, right elbow and so on) is treated as an mask with a single pixel set to 1; the keypoint branch outputs and applies a softmax over the positions.
The ResNet-50-FPN version reaches a keypoint AP of 63.1 on COCO test-dev, above the 61.8 of CMU-Pose+++, the 2016 winner, at 5 images per second. Even though FPN's finest level has a stride of only 4 pixels, RoIAlign still beats RoIPool by 4.4 points on keypoints (Table 6 of the paper), because keypoints need precise positions even more than masks do.
The appendix also runs instance segmentation on Cityscapes. With fine annotations only, ResNet-50-FPN reaches 26.2 AP on the test set, and the biggest gains are on person and car, the classes with the most same-class overlap; fine-tuning from a COCO-pretrained model raises it to 32.0 AP.
Conclusion
Mask R-CNN's changes add up to just three things, an extra FCN mask branch, one sigmoid mask per class, and RoIAlign to remove the two roundings. It beats FCIS+++, which piled on several extra tricks, picks up 2 points of box AP along the way, and with a different output can even do human pose.
Of the three, RoIAlign has had the longest influence. On the same ResNet-50-C4, swapping out RoIPool lifts mask AP from 26.9 to 30.3, and the two-stage models in Detectron2 and MMDetection all use it by default today.
When you write your own RoI feature extraction, first check whether the coordinates get quietly rounded at some step. That is a better use of your time than tuning any hyperparameter.