Mask R-CNN
Mask R-CNN (He et al., 2017) is the natural extension of faster-r-cnn, designed not only to detect objects (draw boxes) but to perform Instance Segmentation — identifying the exact pixels that belong to each object individually.
How It Works
The brilliance of Mask R-CNN was maintaining the fast flow of Faster R-CNN and adding a small parallel network (branch) exclusively in charge of predicting a binary mask (pixel by pixel) for the object bounded by the proposed region.
- Backbone and RPN: Identical to faster-r-cnn. Extracts features from the image and generates Region Proposals.
- RoI Align: Where roi-pooling was previously used (which suffered from severe quantization errors for pixel-level alignment), Mask R-CNN introduced RoIAlign. RoIAlign uses spatial bilinear interpolation to compute the exact value on the feature map with sub-pixel accuracy, maintaining perfect alignment without destructive rounding.
- Parallel Heads: The extracted region feeds two independent paths:
- Main Branch: The classic path for classification and bounding box regression.
- Mask Branch: A small fully convolutional network (FCN) that generates independent binary masks for each of the possible classes.
🧮 Mathematical Foundations (Tripartite Loss)
Training occurs by simultaneously optimizing three distinct tasks through a combined global loss function:
Eq. 1: Tripartite loss function of Mask R-CNN.
Where:
- : total network loss.
- : ROI classification loss (what the object is).
- : bounding box regression loss (where the strict limits of the box are).
- : average binary cross-entropy (BCE) loss specifically focused on predicting the correct mask for the region.
The Mathematics of the Mask Branch
The mask branch generates an output of dimension , indicating binary masks of resolution (one autonomous mask for each of the known classes).
Unlike traditional semantic segmentation (where all classes compete for the same pixel in a multinomial global Softmax), Mask R-CNN completely decouples mask classification, applying Sigmoid in isolation.
Eq. 2: Isolated pixel-wise binary cross-entropy (BCE) for the true class.
Where:
- : the true (ground truth) class of the object (identified in the training label).
- : true binary label of the pixel ( if the pixel is the object, if it is background).
- : probability (Sigmoid activator output) that pixel belongs to the object in the class mask.
- : total number of pixels in the generated mask grid ().
Only the mask associated with the true class of the object () actively contributes to the loss, totally ignoring the masks generated for the other classes. This decoupling prevents mathematical interference and was the secret to the model’s spectacular segmentation results.
Related: faster-r-cnn · roi-pooling · roi-align