Back to paper library
arXiv 2020NeurIPS 2020SegmentationPaper notes

SOLOv2

Tailor-Made

Original paper

SOLOv2: Dynamic and Fast Instance Segmentation

Paper authors

Xinlong Wang · Rufeng Zhang · Tao Kong · Lei Li · Chunhua Shen

Publication
NeurIPS 2020Conference
First submitted to arXiv
arXiv:2003.10152
Cite this paper · BibTeX

The citation identifies the linked source version. It cites the original paper and its authors.

@misc{segmentationsolov22020,
  title = {{SOLOv2: Dynamic and Fast Instance Segmentation}},
  author = {Xinlong Wang and Rufeng Zhang and Tao Kong and Lei Li and Chunhua Shen},
  year = {2020},
  eprint = {2003.10152},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2003.10152}
}
On this page

SOLO showed that instance segmentation can be done without boxes: divide the image into an S×SS \times S grid, and whichever cell an object's center falls in takes charge of it; the mask branch outputs S2S^2 masks, with mask kk handling the object in cell kk.

This approach carries two obvious burdens. One is those S2S^2 masks, 1,600 of them at the finest FPN level, the vast majority empty. The other is post-processing, since NMS on masks is much slower than NMS on boxes; computing the IoU of two masks costs far more than for two boxes.

Three months later, the same group of authors (Xinlong Wang and Chunhua Shen of the University of Adelaide, Tao Kong and Lei Li of ByteDance, joined by Rufeng Zhang of Tongji University) delivered SOLOv2, with one fix for each burden: dynamic convolution and Matrix NMS.

Defining the Problem

The authors start by rewriting SOLO's mask branch.

The last layer of the mask branch applies a 1×11 \times 1 convolution to an H×W×EH \times W \times E feature FF and outputs S2S^2 channels. Broken apart, the mask for cell (i,j)(i, j) is just:

Mi,j=Gi,j∗FM_{i,j} = G_{i,j} * F

Gi,jG_{i,j} is a 1×1×E1 \times 1 \times E kernel, which is to say an EE-dimensional vector; Mi,jM_{i,j} is an H×WH \times W mask containing only the object centered in cell (i,j)(i, j).

So SOLO is really learning two things, a feature FF and S2S^2 fixed kernels GG. It computes all S2S^2 masks MM and trains on every one of them, yet the objects in an image are usually sparse, and only a handful of masks are actually useful.

If FF and GG are learned separately, then at inference you can pick out only the cells that contain objects and convolve FF with their GG, without computing the thousand-plus empty masks. Going a step further, if GG is no longer a fixed parameter but is generated dynamically from the input image, every cell gets a segmenter tailor-made for this image and this location.

Solving the Problem

Learning Kernels and Features Separately

Diagram compiled for this note. On the left is the 5×5 output of the kernel branch; cells (1, 3) and (3, 1) contain objects, and each pulls out a kernel vector, G₁,₃ (blue) and G₃,₁ (orange). In the middle is a stack of shared mask features F, of size H×W×E, fused from the FPN levels at 1/4 resolution. Each of the two kernels is convolved with F, giving the two masks M₁,₃ and M₃,₁ on the right, each containing only one object.
Drawn for this note from Section 2.1 of the paper; the grid size and object positions are illustrative.

SOLOv2 has three parts: the category branch (the same as SOLO's), the kernel branch and the mask feature branch.

Kernel branch. At each FPN level, the features are first resized to S×S×CS \times S \times C and passed through 4 convolution layers, and a final 3×33 \times 3 convolution outputs DD channels, giving kernels GG of size S×S×DS \times S \times D. Each cell's DD numbers are the weights of one kernel: to generate a 1×11 \times 1 kernel over EE input channels, D=ED = E; for 3×33 \times 3, D=9ED = 9E. The output has no activation function.

Because each kernel is predicted "per cell", it is tied to location from the start. Before the first convolution layer, normalized xx and yy coordinates are concatenated as well.

Mask feature branch. The authors tried two designs. One, like SOLO, computes a separate mask feature at each FPN level; the other fuses all levels into one unified feature. The latter works better and is the one adopted.

The fusion borrows the semantic segmentation branch of Panoptic FPN: each of P2 to P5 repeats "3×33 \times 3 convolution, GroupNorm, ReLU, 2× upsampling" until it reaches 1/4 resolution, they are all summed, and a 1×11 \times 1 convolution gives the H×W×EH \times W \times E feature FF. Coordinates are concatenated only on the deepest level, P5 (1/32), before any convolution or upsampling.

Assembly. At inference, cells whose category score falls below 0.1 are filtered out first, and each remaining cell takes its own Gi,jG_{i,j}, convolves it with FF, applies a sigmoid and binarizes at 0.5, giving each object's mask.

The loss is the same as SOLO's, with Focal Loss for categories and Dice Loss for masks.

How It Differs from YOLACT

This structure looks a bit like YOLACT, since both are "one shared thing, plus a set of numbers for each object". YOLACT multiplies 32 prototypes by 32 coefficients; SOLOv2 takes an EE-channel feature and applies a 1×11 \times 1 convolution with the EE-dimensional kernel predicted at each cell, which is in essence a weighted combination too.

The differences the authors single out lie elsewhere. YOLACT's coefficients hang on anchors and are normalized with tanh, and at inference it has to detect boxes first and then use them to crop the assembled masks; SOLOv2 has no anchors, needs no normalization and needs no boxes at all. Masks come straight from kernels determined by location.

Matrix NMS

The second problem is NMS.

Traditional NMS is greedy and sequential: sort by score, start from the highest, delete lower-scoring predictions that overlap it too much, then move on to the next prediction still alive. Soft-NMS doesn't delete outright but lowers scores according to the overlap, though it still has to process predictions one at a time, recursively.

YOLACT's Fast NMS turns it into matrix operations, at the cost of letting "predictions that have already been deleted delete others too", so it deletes too much.

Matrix NMS also finishes in one pass of matrix operations, but it looks at the problem from a different angle: how much a prediction mjm_j gets suppressed depends on two things.

  • (a) The penalty from each higher-scoring mim_i, expressed as a function of the overlap, f(ioui,j)f(\text{iou}_{i,j}).
  • (b) How likely mim_i itself is to be suppressed. If mim_i is itself a duplicate prediction that ought to be deleted, its penalty on mjm_j should be discounted.

(b) is hard to compute exactly, so the authors approximate it by the largest overlap between mim_i and any "prediction scoring higher than it":

f(iou⋅,i)=min⁡∀sk>sif(iouk,i)f(\text{iou}_{\cdot,i}) = \min_{\forall s_k > s_i} f(\text{iou}_{k,i})

The final decay factor for mjm_j is:

decayj=min⁡∀si>sjf(ioui,j)f(iou⋅,i)\text{decay}_j = \min_{\forall s_i > s_j} \frac{f(\text{iou}_{i,j})}{f(\text{iou}_{\cdot,i})}

The new score is sj⋅decayjs_j \cdot \text{decay}_j. ff can be linear, 1−iou1 - \text{iou}, or Gaussian.

These formulas look a bit convoluted, and walking through a small example makes them clear. Take three predictions sorted by score: s1=0.9s_1 = 0.9, s2=0.8s_2 = 0.8, s3=0.7s_3 = 0.7, with pairwise IoUs iou1,2=0.6\text{iou}_{1,2} = 0.6, iou1,3=0.1\text{iou}_{1,3} = 0.1 and iou2,3=0.55\text{iou}_{2,3} = 0.55. Use the linear ff.

  • m1m_1. Nothing scores higher, so no decay.
  • m2m_2. The only higher-scoring prediction is m1m_1, which no one suppresses, so the denominator is 1−0=11 - 0 = 1. The decay factor is (1−0.6)/1=0.4(1 - 0.6) / 1 = 0.4, and the score becomes 0.8×0.4=0.320.8 \times 0.4 = 0.32.
  • m3m_3. Both m1m_1 and m2m_2 count. From m1m_1, it's (1−0.1)/1=0.9(1 - 0.1) / 1 = 0.9. From m2m_2, the denominator uses how much m2m_2 is suppressed by m1m_1, 1−0.6=0.41 - 0.6 = 0.4, so it's (1−0.55)/0.4=1.125(1 - 0.55) / 0.4 = 1.125. Taking the minimum, 0.9, the score becomes 0.7×0.9=0.630.7 \times 0.9 = 0.63.

Although m2m_2 overlaps m3m_3 quite a bit, m2m_2 itself has already been heavily suppressed by m1m_1, so its penalty on m3m_3 is discounted (a ratio above 1 amounts to no penalty).

Compare the other two kinds of NMS on the same numbers (threshold 0.5). Traditional NMS: m2m_2's IoU of 0.6 with m1m_1 exceeds the threshold, so it's deleted; m3m_3 overlaps m1m_1 by only 0.1 and is kept, and since m2m_2 is already gone, it can't delete m3m_3. Fast NMS: m3m_3 is compared with every prediction scoring higher, and its largest IoU, 0.55 with m2m_2, exceeds the threshold, so it's deleted. That's Fast NMS deleting too much, while Matrix NMS agrees with traditional NMS and can still be computed for the whole batch in one go.

In implementation, once the top NN predictions are sorted, the intersections of binary masks can be computed with a single matrix multiplication to give the N×NN \times N IoU matrix; taking the upper triangle and the maximum of each column gives iou⋅,i\text{iou}_{\cdot,i}; after all the ratios are computed, the minimum of each column is each prediction's decay factor. There are no loops at all, and the authors say a simple Python implementation handles 500 masks in under 1 millisecond.

Discussion

Main Results

The training setup is the same as SOLO's: 8 GPUs, 16 images per batch, 36 epochs, shorter side randomly scaled from 640 to 800. Results on COCO test-dev (compiled from Table 1 of the paper):

MethodBackboneAPAPSAPL
Mask R-CNNR-101-FPN35.715.552.4
BlendMaskR-101-FPN38.418.253.3
SOLOR-101-FPN37.816.454.2
SOLOv2R-50-FPN38.816.556.2
SOLOv2R-101-FPN39.717.357.4
SOLOv2DCN-101-FPN41.718.061.6

SOLOv2 with ResNet-101 is 1.9 AP above SOLO, and the authors say it's 33% faster as well. The advantage on large objects is especially clear, 5.0 above Mask R-CNN. SOLOv2's masks come from a unified feature at 1/4 resolution, unlike Mask R-CNN's, which are limited to small 28×28 boxes.

On LVIS v0.5, with more than a thousand classes, SOLOv2 is also about 1 AP above Mask R-CNN.

Ablations

These ablations are all on the COCO validation set (Table 3 of the paper):

  • Kernel shape. 3×3×643 \times 3 \times 64 and 1×1×641 \times 1 \times 64 both give 37.4, so the spatial size makes no difference; raising the input channels from 128 to 256 adds 0.4, and 512 brings no further gain. So the final choice is 1×1×2561 \times 1 \times 256, and each cell has to predict only 256 numbers.
  • Coordinates. With no coordinates in either branch, it's 36.3; only in the kernel branch, still 36.3; only in the mask feature branch, 37.1; in both, 37.8. The authors' explanation is that if the kernel branch doesn't know location, objects that look alike get the same kernel; if the mask feature doesn't know location, it can't tell how to arrange pixels into the channels that line up with the kernels.
  • Mask features. A separate feature per FPN level gives 37.3 and one unified feature gives 37.8, with the difference mainly on medium and large objects. When levels are separate, large objects are assigned to the high levels with the lowest resolution, so their boundaries naturally come out coarser.
  • NMS. This one measures NMS alone, with the IoU matrix computed in advance:
MethodRecursiveTimeAP
Hard-NMSYes9 ms36.3
Soft-NMSYes22 ms36.5
Fast NMSNo< 1 ms36.2
Matrix NMSNo< 1 ms36.6

Matrix NMS is both fast and accurate. Fast NMS is just as fast, but because it deletes too much, its AP ends up even lower than traditional Hard-NMS.

Real-Time Versions

The authors built two lightweight versions. SOLOv2-448 cuts the prediction head to 2 convolution layers with a 448 shorter side, at 46.5 FPS and 34.0 AP; SOLOv2-512 uses 3 convolution layers with a 512 shorter side and adds deformable convolution to the backbone and the last layer of the prediction head, at 31.3 FPS and 37.1 AP. On COCO test-dev, the latter is more than 7 points above YOLACT-550 (29.8), and it's still real-time.

Detection and Panoptic Segmentation

SOLOv2 predicts no boxes at all, but take the bounding rectangle of each mask as a box and its detection box AP comes to 44.9, with no box supervision of any kind during training.

Add a semantic segmentation branch similar to the mask feature branch and merge the outputs with Panoptic FPN's method, and it does panoptic segmentation. On the COCO validation set, SOLOv2 (ResNet-50) reaches 42.1 PQ, above Panoptic FPN's 39.0 and every other box-free method. Broken down, though, PQ on things is 49.6 and on stuff only 30.7, and on stuff it trails UPSNet (33.4), which uses deformable convolution, by a fair margin.

Conclusion

SOLOv2 splits SOLO's mask branch into two halves, "kernels" and "features". From the image content and its own location, each cell predicts a 1×11 \times 1 kernel and convolves a shared high-resolution feature with it. Where 1,600 masks used to be computed, now only the few with objects are.

Matrix NMS rewrites the idea of Soft-NMS as a single matrix operation, correcting each penalty by "whether whoever suppresses you was suppressed too" and computing both factors in one go, with no recursion and none of Fast NMS's over-deletion.

This dynamic approach of "each instance generates its own kernel" later turned, in the K-Net and MaskFormer line, into a dot product between query vectors and pixel features. Matrix NMS ports easily to other detectors and segmenters, needing only a few lines of matrix operations; just note that what it outputs are decayed scores, and you still have to set a threshold and take the top kk yourself.