K-Net: Towards Unified Image Segmentation
- Publication
- NeurIPS 2021Conference
- First submitted to arXiv
- arXiv:2106.14855
Cite this paper · BibTeX
The citation identifies the linked source version. It cites the original paper and its authors.
@misc{segmentationknet2021,
title = {{K-Net: Towards Unified Image Segmentation}},
author = {Wenwei Zhang and Jiangmiao Pang and Kai Chen and Chen Change Loy},
year = {2021},
eprint = {2106.14855},
archivePrefix = {arXiv},
url = {https://arxiv.org/abs/2106.14855}
}
The last layer of a semantic segmentation network is, when you get down to it, a set of convolution kernels. One kernel per class is convolved with the feature map, each class gets a score map, and each pixel goes to the class with the highest score. In use for years ever since FCN, it's simple and elegant.
Instance segmentation could never work this way. The number of objects in an image isn't fixed, so you can't prepare a fixed number of kernels in advance; everyone had to take a detour instead, with Mask R-CNN detecting boxes first and SOLO assigning by grid cells, and both still relying on NMS at the end to remove duplicate results.
Wenwei Zhang and Chen Change Loy of Nanyang Technological University in Singapore, with Jiangmiao Pang and Kai Chen of SenseTime and Shanghai AI Laboratory, wanted to try something: if each kernel were responsible for only "one object", could instance segmentation use the same method as semantic segmentation? They call this framework K-Net, where K stands for kernel.
Defining the Problem

Start with semantic segmentation. Given a feature map , prepare kernels , and convolution gives masks:
For semantic segmentation, is the number of classes and is a softmax, so each pixel goes to one class. In the left column of the figure, the "car" kernel cuts out both cars, because it cares only about the class, not about which car is which.
K-Net's idea is to use the same formula for instances. Prepare "instance kernels" (100 in the experiments), each cutting out at most one object, and switch to a sigmoid. Separating different objects and cutting out their masks then happen in the same step, with no boxes and no clustering. Put semantic kernels and instance kernels together, and you have panoptic segmentation.
But there are two difficulties here.
First, instances have no shared features. All cars look like cars, so the "car" kernel can learn to remember what a car looks like; but what is "instance kernel number 37" supposed to handle? It has to accurately grab one particular object in every image, and those objects all differ in size, appearance and position. A fixed set of kernels can't do that.
Second, how do you decide which kernel handles which object? The assignment of semantic kernels is fixed, with kernel 3 always "car"; the number of instance kernels doesn't match the number of objects in an image, so an assignment rule is needed.
There were already "dynamic kernel" approaches such as SOLOv2, CondInst and Panoptic FCN, but they all generate one kernel per location on a dense grid and then pick the useful ones, so duplicate kernels still have to be removed with NMS or extra fusion.
Solving the Problem
Revising Kernels with Last Round's Masks

K-Net's answer to the first difficulty is to let each kernel revise itself according to what it currently cuts out. The authors call this module the kernel update head:
At the start, a set of learnable static kernels is convolved with the features to give a first version of the masks, . These masks are coarse, but they already roughly indicate "which group of pixels each kernel is currently looking at". The kernel update head then does three things.
① Group features. Each mask weights the feature map, summing up the features of the group of pixels each kernel is responsible for:
is , so each kernel gets one vector representing "what its own group of pixels looks like".
② Adaptive update. The masks aren't necessarily accurate, and may include pixels of other objects. So instead of using directly as the new kernel, the authors learn two gates that decide whom the new kernel should listen to:
and are all linear layers ( followed by LayerNorm), is element-wise multiplication and is the sigmoid. The two gates decide channel by channel how much of each dimension of the new kernel comes from this image's group feature and how much keeps the original kernel . The authors liken it to the weighted sum in self-attention, except that the weights come from element-wise multiplication followed by a sigmoid instead of a dot product.
③ Kernels interact. The updated kernels then pass through one layer of multi-head attention and an FFN, letting the kernels exchange information with each other, along the lines of "I've already got the car on the left, you take the one on the right". The output is the new kernels .
Finally, passes through a small network and is convolved with to give the new masks ; is also used to predict each mask's class.
This process can repeat. The more accurate the masks, the less noise in the gathered group features, the more discriminative the kernels, and the more accurate the next round's masks. K-Net repeats it 3 times by default. And the kernel update head doesn't care whether a kernel is semantic or instance; it updates both the same way.
Assigning Objects by Bipartite Matching
The answer to the second difficulty is borrowed from DETR: bipartite matching. At every training step, the masks predicted by the 100 instance kernels are matched one-to-one with the annotated objects in the image, with a matching cost of the same form as the loss; each matched kernel learns its object, and unmatched ones learn "no object".
Unlike DETR, K-Net's matching looks only at masks, with no boxes. The loss is Focal Loss for classification plus cross-entropy and Dice Loss for masks, weighted 2, 1 and 4 respectively. Dice handles the severe foreground–background imbalance when an object occupies only a small patch of the image, for the same reason as in SOLO.
Because each object is matched to only one kernel, no two kernels fight over the same object at inference, so K-Net needs no NMS.
Applying It to Three Tasks
- Panoptic segmentation. Features come from Semantic FPN, with positional encoding added to the deepest level, P5. Instances and semantics each get their own branch to produce features, which are convolved with the instance kernels and semantic kernels respectively; then the stuff classes (sky, road and so on) from the semantic masks are concatenated with the instance masks, the kernels likewise, and everything goes into the kernel update head together. Finally, masks are sorted by classification score and pasted on in order.
- Instance segmentation. Drop the concatenation and keep only the instance kernels. The semantic branch is still kept, with its labels converted directly from the instance annotations, so no extra data is needed.
- Semantic segmentation. Simpler still. Attach the kernel update head to any model that "classifies with static semantic kernels"; FCN, PSPNet, DeepLabv3 and UperNet all work.
Discussion
Panoptic Segmentation
Results on COCO panoptic segmentation (compiled from Table 1 of the paper; things/stuff PQ in parentheses):
| Method | Backbone | Epochs | PQ |
|---|---|---|---|
| Panoptic FPN | R50 | 36 | 41.5 (48.5/31.1) |
| DETR | R50 | 300+25 | 43.4 (48.2/36.3) |
| Panoptic FCN | R50 | 36 | 43.6 (49.3/35.0) |
| K-Net | R50 | 36 | 47.1 (51.7/40.3) |
(All on the validation set.)
With the same ResNet-50, K-Net is 3.5 PQ above Panoptic FCN and 3.7 above DETR, which needs over 300 epochs of training. The gain on stuff is especially large, with 40.3 at least 4 points above every other method.
With Swin-L, it gets 55.2 on test-dev, beating its contemporaries MaskFormer (53.3), Max-DeepLab (51.3) and Panoptic SegFormer (54.4). And K-Net trains for only 36 epochs, against MaskFormer's 300; the authors say it takes about 2 days and 18 hours on 16 GPUs.
Instance Segmentation
On the COCO validation set, with the same ResNet-50-FPN and 36 epochs of training (Table 2 of the paper):
| Method | No box | No NMS | AP | APS | APL | FPS | Params |
|---|---|---|---|---|---|---|---|
| Mask R-CNN | 37.1 | 18.7 | 53.9 | 17.5 | 44.2M | ||
| SOLOv2 | ✓ | 37.5 | 15.8 | 56.6 | 17.7 | 33.9M | |
| Cascade Mask R-CNN | 38.5 | 19.3 | 55.6 | 10.3 | 77.1M | ||
| K-Net | ✓ | ✓ | 37.8 | 16.9 | 57.5 | 21.2 | 37.3M |
| K-Net (256 kernels) | ✓ | ✓ | 38.6 | 19.1 | 57.7 | 19.8 | 37.3M |
K-Net is the only method in the table that uses neither boxes nor NMS, and it's also the fastest. With 256 instance kernels, it matches Cascade Mask R-CNN while being 92% faster with only half the parameters.
K-Net's weak spot is small objects. The 100-kernel version gets 16.9 small-object AP, nearly 2 points below Mask R-CNN; on large objects it leads all the way.
Semantic Segmentation
With the kernel update head attached to various semantic segmentation models, the results on the ADE20K validation set (Table 3a of the paper, ResNet-50):
| Model | Original | +K-Net |
|---|---|---|
| FCN | 36.7 | 43.3 |
| PSPNet | 42.6 | 43.9 |
| DeepLabv3 | 43.5 | 44.6 |
| UperNet | 42.4 | 43.6 |
| UperNet (Swin-L) | 50.6 | 52.0 |
FCN jumps by 6.6 in one go, overtaking the original PSPNet and UperNet and coming close to DeepLabv3. Even the already strong Swin-L UperNet gains another 1.4. Finally, with 640×640 inputs and test-time augmentation, it reaches 54.3, the best single-model score on ADE20K at the time.
Ablations
These ablations are on COCO instance segmentation, with ResNet-50 and 12 epochs of training (Table 4 of the paper):
- The two parts of the kernel update head. Without either, it's only 10.0 AP; with only the adaptive update, 22.6; with only kernel interaction, 31.2; with both, 34.1. Neither can be dropped, and the interaction between kernels contributes more.
- Position information. With no position information it's 30.9, with coordinate convolution 34.0, with positional encoding 34.1, and adding both is no better.
- Number of rounds. One round gives 21.8, 2 rounds 32.1, 3 rounds 34.1, and 4 or 5 rounds both 34.5; each extra round slowly lowers the speed from 24.0 images per second to 18.9.
- Number of kernels. 50 gives 32.7, 100 gives 34.1, 256 gives 34.7, and going on to 300, 512 or 768 all stop at 34.9. COCO averages only 7.7 objects per image, so 100 kernels are more than enough.
The number of update rounds for semantic segmentation shows a similar trend. FCN with K-Net on ADE20K goes from 36.7 at 0 rounds to 44.1 at 5 rounds, and more rounds start to hurt, down to 42.6 at 7.
What the Kernels Learn
The authors averaged the masks of the 100 instance kernels over 5,000 validation images, and each kernel specializes in objects of a certain size in a certain region of the frame. This resembles the effect of SOLO's hard assignment of positions by grid cells, except that K-Net's division of labor is learned on its own.
They also looked at how the masks change round by round. The masks cut out by the static kernels are quite incomplete, often missing rivers and buildings; after one update round the content is filled in, but the boundaries are still coarse; over a few more rounds the boundaries gradually improve, and the classification confidence rises with them.
Conclusion
K-Net unifies the three kinds of segmentation with a very plain view, in which each kernel cuts out one mask, a semantic kernel handles one class and an instance kernel handles one object. What lets each instance kernel actually lock onto one object is the update head that repeatedly revises the kernels, together with one-to-one bipartite matching. The result is a framework with no boxes and no NMS that took the best results of its time on both panoptic and semantic segmentation, and drew level with Cascade Mask R-CNN on instance segmentation.
It took the opposite direction from MaskFormer in the same period. MaskFormer rewrote semantic segmentation as instance-style "mask classification"; K-Net rewrote instance segmentation as semantic-style "one kernel, one mask". The two paths finally met in Mask2Former: queries are kernels, the queries are updated layer by layer, and the masks get more accurate layer by layer along with them.
When tuning K-Net, the two most direct knobs are the number of update rounds and the number of kernels, and both saturate quickly. After 3 rounds, there's only 0.4 more AP to gain, and going from 100 to 256 kernels adds only 0.6. Keep an eye on small objects, where the 100-kernel version still trails Mask R-CNN by nearly 2 points.