Back to paper library
arXiv 2022CVPR 2022SegmentationPaper notes

GroupViT

Grouping on Its Own

Original paper

GroupViT: Semantic Segmentation Emerges from Text Supervision

Paper authors

Jiarui Xu · Shalini De Mello · Sifei Liu …

Show all 7 authors

Jiarui Xu · Shalini De Mello · Sifei Liu · Wonmin Byeon · Thomas Breuel · Jan Kautz · Xiaolong Wang

Publication
CVPR 2022Conference
First submitted to arXiv
arXiv:2202.11094
Cite this paper · BibTeX

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

@misc{segmentationgroupvit2022,
  title = {{GroupViT: Semantic Segmentation Emerges from Text Supervision}},
  author = {Jiarui Xu and Shalini De Mello and Sifei Liu and Wonmin Byeon and Thomas Breuel and Jan Kautz and Xiaolong Wang},
  year = {2022},
  eprint = {2202.11094},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2202.11094}
}
On this page

The most expensive part of training a segmentation model is annotation. Someone has to paint a class onto every image, pixel by pixel. PASCAL VOC has only a little over ten thousand images and ADE20K twenty thousand, and that's already years of work.

The web, meanwhile, has hundreds of millions of images that come with a line of text. CLIP showed that these "image plus a sentence" pairs can teach very strong image classification, but a sentence describes only the image as a whole, not where each thing is.

Jiarui Xu and Xiaolong Wang of UC San Diego, together with a team from NVIDIA, wanted to know whether a network given nothing but this coarse text supervision could learn on its own to cut an image into meaningful regions. Their answer is GroupViT. It adds to ViT a grouping mechanism that merges similar tokens, never looks at a single pixel annotation during training, and can go straight to semantic segmentation at the end.

Defining the Problem

Before deep learning, segmentation was often done in two steps. First the pixels were "grouped" into regions (superpixels or clustering, for example), and then each region was classified. With end-to-end deep networks the grouping step disappeared. The network learns each pixel's class directly from pixel-level labels, and grouping is just a by-product hidden inside.

The authors want to put the grouping mechanism back into the network. If the network's structure itself merges similar regions, it may not need pixel-level labels at all; knowing only that "this picture has two elephants and a jungle" might be enough for it to learn to separate the elephants from the jungle.

There are two difficulties. First, ViT works on a regular grid of patches, so how do you get it to output regions of arbitrary shape? Second, with only one sentence describing the whole image, how do you make each region correspond to something in the text?

Solving the Problem

A Transformer That Merges in Stages

Original Figure 2: (a) GroupViT's architecture and training pipeline. The image is cut into patches and linearly projected, then fed into Transformer layers together with a set of learnable group tokens, after which a Grouping Block merges the image tokens into fewer segment tokens; the second stage adds a smaller set of group tokens and repeats the Transformer layers and Grouping Block once more; finally, Transformer layers, average pooling and an MLP produce the image embedding, which is contrasted with the output of the text encoder. The images on the right show the regions found at the two stages: the first stage splits the elephants into parts such as trunks and legs, and the second stage merges them into whole elephants and the forest in the background. (b) The Grouping Block: group tokens and segment tokens pass through the linear projections Wq and Wk to compute similarity, are assigned with Gumbel softmax, and are then merged with Wv and Wo into new segment tokens.
Original Figure 2, Xu et al., from PDF page 4, CC BY 4.0.

GroupViT's skeleton is ViT-S, 12 Transformer layers of 384 dimensions each. The difference is that these 12 layers are split into stages, and at the end of each stage a Grouping Block merges the tokens into fewer, larger regions.

Let's follow a 224×224 training image through the two-stage version the paper ends up using.

  1. Patches. 16×16 patches, 196 image tokens in all.
  2. Stage one. A separate set of 64 learnable group tokens is concatenated with the 196 image tokens and passed through 6 Transformer layers. In self-attention the group tokens can see every image token, and each group token gradually absorbs some kind of visual concept.
  3. First grouping. The Grouping Block assigns the 196 image tokens to the 64 group tokens; tokens in the same group merge into one new segment token, leaving 64.
  4. Stage two. Another 8 group tokens go through 3 Transformer layers with the 64 segment tokens, followed by another grouping, which leaves 8 segment tokens.
  5. Output. After the last 3 Transformer layers, the 8 segment tokens are averaged and passed through an MLP to get the embedding of the whole image, zIz^I.

From the end of the first stage on, the network no longer works on a regular grid but on regions of arbitrary shape.

Grouping Block

How is the grouping done? First compute the similarity between every group token g^i\hat{g}_i and every segment token s^j\hat{s}_j, and take a softmax over the group tokens:

Ai,j=exp⁡(Wqg^i⋅Wks^j+γi)∑k=1Mexp⁡(Wqg^k⋅Wks^j+γk)A_{i,j} = \frac{\exp(W_q \hat{g}_i \cdot W_k \hat{s}_j + \gamma_i)}{\sum_{k=1}^{M} \exp(W_q \hat{g}_k \cdot W_k \hat{s}_j + \gamma_k)}

γ\gamma is random noise drawn from a Gumbel distribution. This is Gumbel-Softmax, which adds a little randomness to the assignment during training.

Each segment token is then assigned only to the group with the highest similarity, that is, the argmax is taken and turned into a one-hot vector. But argmax isn't differentiable, so the authors use the straight-through trick:

A^=one-hot(Aargmax)+A−sg(A)\hat{A} = \text{one-hot}(A_{\text{argmax}}) + A - \text{sg}(A)

sg\text{sg} is stop-gradient. In the forward pass, A^\hat{A} is the one-hot hard assignment; in the backward pass, the gradient follows the soft assignment AA. The authors call this hard assignment.

Finally, each group's new segment token is the weighted average of the tokens assigned to that group, plus the group token itself:

si=g^i+Wo∑jA^i,jWvs^j∑jA^i,js_i = \hat{g}_i + W_o \frac{\sum_j \hat{A}_{i,j} W_v \hat{s}_j}{\sum_j \hat{A}_{i,j}}

The authors point out that this Grouping Block closely resembles a single iteration of Slot Attention. The difference is that Slot Attention learns instance-level grouping without supervision, whereas GroupViT learns semantic-level grouping under weak supervision from text.

Trained on Text Alone

Training is contrastive learning, as in CLIP. In a batch of BB image–text pairs, matching image and text embeddings are pulled together and non-matching ones pushed apart.

The authors also add a multi-label contrastive loss. K=3K = 3 nouns are picked at random from each caption and dropped into templates CLIP used, such as "A photo of a {noun}", producing 3 new sentences. The example in the paper's figure is "Easter bunny rabbit on the bed," from which rabbit and bed are extracted to produce sentences like "A photo of a rabbit" and "A picture of a bed." Besides its original caption, each image now has 3 more positives.

The motivation is that objects in an image usually correspond to nouns in the sentence. And since inference classifies by putting class names into templates, the model might as well get used to that sentence pattern during training.

The training data is CC12M plus a filtered YFCC, about 26 million image–text pairs in total, with a batch size of 4,096 and 30 epochs of training.

Zero-Shot Transfer to Segmentation

Original Figure 6: results on three PASCAL VOC images. Each row shows, from left to right, the original image, the first-stage grouping (one color per group), the second-stage grouping, the prediction once classes are added, and the annotation. The first-stage regions are more fragmented; the second-stage ones already roughly match whole objects.
Original Figure 6, Xu et al., from PDF page 8, CC BY 4.0.

Once trained, GroupViT can do semantic segmentation directly, without any fine-tuning:

  1. The image goes into GroupViT, but the final average pooling is skipped, keeping the embeddings of the 8 segment tokens.
  2. Multiplying the assignment matrices of the two stages tells you which final segment each patch belongs to.
  3. The dataset's class names are put into the templates, and the text encoder gives an embedding for each class.
  4. Each segment goes to the class whose text embedding is most similar.

Background is handled separately. If a segment's similarity to every class (after the softmax) is below a threshold, it's treated as background. The threshold is 0.9 on VOC and 0.5 on PASCAL Context.

Discussion

Ablations

All ablations are on the PASCAL VOC 2012 validation set, using a version with a single grouping stage trained only on CC12M:

Hard assignmentMulti-label lossmIoU
12.0
✓36.7
✓25.1
✓✓39.3

(From Table 1 of the paper.)

Hard assignment is the most critical item. The soft-assignment version gets only 12.0, and switching to hard assignment jumps straight to 36.7. The authors' guess is that under soft assignment every token gives a little to every group, so the groups' features end up too similar and assigning text labels gets blurry; hard assignment makes the groups mutually exclusive and easier to tell apart. The multi-label loss helps in both cases, and together they reach 39.3.

The number of group tokens matters too: 37.1 with 16, 38.3 with 32 and 39.3 with 64. For the number of output segments, 8 is best. With 16 group tokens, 4 outputs get only 28.6 and 8 get 37.1; with 64 group tokens, 16 outputs actually drop from 39.3 to 38.0.

One stage or two? Trained on CC12M alone, two stages beat one by 1.8. With YFCC added to the training, one stage actually drops to 37.2, while two stages jump to 52.3. The benefit of merging in stages only really shows once there's more data.

What the Group Tokens Learned

Original Figure 7: the regions several group tokens attend to on PASCAL VOC images. In the first stage, group 5 focuses on eyes and group 36 on limbs (hands when there are people, feet when there are animals); in the second stage, group 6 corresponds to grass, group 4 to bodies and group 7 to faces.
Original Figure 7, Xu et al., from PDF page 8, CC BY 4.0.

The first-stage group tokens learn mid-level concepts such as eyes and limbs. One interesting case is group token 36, which looks at hands in images with people and at feet in images with birds or dogs, capturing a cross-class concept along the lines of "the ends of limbs." The second-stage group tokens correspond to high-level concepts such as grass, bodies and faces, assembling the parts from the first stage.

Compared with Other Methods

The authors first compare against "a plain ViT trained the CLIP way, plus non-parametric clustering" (Table 4 of the paper). Per-pixel classification gets 20.1, K-means 25.0, Mean-shift 20.7 and spectral clustering 19.7; GroupViT gets 52.3, a wide margin.

More convincing is the comparison with methods that need fine-tuning (Table 5 of the paper):

PretrainingSupervisionZero-shotVOCContext
DeiT (ImageNet)ClassNo53.035.9
DINO (ImageNet)Self-sup.No39.120.4
MoCo (CC12M+YFCC)Self-sup.No36.123.0
GroupViT (CC12M+YFCC)TextYes52.322.4

The other methods all fine-tune a segmentation head on the VOC or Context training set; GroupViT uses none of those annotations. On VOC it's only 0.7 behind DeiT, which was pretrained with ImageNet class labels and then fully fine-tuned.

Background Is the Weak Spot

On PASCAL Context, though, GroupViT gets only 22.4, clearly lower than on VOC and behind DeiT's 35.9.

The authors dug into why in the appendix. Context has many background classes, such as ground, road and wall, and the IoU on these classes is only about 1.5. They found that GroupViT actually groups these pixels correctly. The trouble comes in the classification that follows, where the whole group is matched to the wrong class. Image captions on the web rarely mention "ground" or "wall," so the model never learned how these words correspond to the image.

They also ran an oracle experiment that keeps GroupViT's grouping but decides each group's class by "the annotation with the largest IoU against it." VOC goes from 52.3 to 73.7, Context from 22.4 to 54.6 and COCO from 24.3 to 54.0. The grouping itself is good; the bottleneck is the step that maps regions to text.

The authors also acknowledge another limitation. GroupViT's architecture has no segmentation-specific design at all, with no atrous convolution, no pyramid pooling and no U-Net-style decoder. On top of that, it outputs only 8 regions at the end, so when an image holds many things, there aren't enough regions to go around.

Conclusion

GroupViT showed that, without a single pixel annotation and from nothing but web images and their captions, semantic segmentation can still emerge on its own. What makes it work is a network structure that groups by itself, using group tokens plus hard assignment to merge patches into parts, and parts into objects, stage by stage.

Its ceiling is just as clear. The grouping is good, as the oracle experiment proves; what really holds it back is "what is this region called," especially for background classes that rarely show up in captions.

That's also the biggest limitation when moving it to other domains. Whatever you want to segment has to show up in captions first. Nobody on the web writes "there's a floor in this photo," so GroupViT never learns floors.