GroupViT: Semantic Segmentation Emerges from Text Supervision
- 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}
}
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

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.
- Patches. 16×16 patches, 196 image tokens in all.
- 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.
- 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.
- 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.
- 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, .
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 and every segment token , and take a softmax over the group tokens:
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:
is stop-gradient. In the forward pass, is the one-hot hard assignment; in the backward pass, the gradient follows the soft assignment . 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:
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 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. 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

Once trained, GroupViT can do semantic segmentation directly, without any fine-tuning:
- The image goes into GroupViT, but the final average pooling is skipped, keeping the embeddings of the 8 segment tokens.
- Multiplying the assignment matrices of the two stages tells you which final segment each patch belongs to.
- The dataset's class names are put into the templates, and the text encoder gives an embedding for each class.
- 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 assignment | Multi-label loss | mIoU |
|---|---|---|
| 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

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):
| Pretraining | Supervision | Zero-shot | VOC | Context |
|---|---|---|---|---|
| DeiT (ImageNet) | Class | No | 53.0 | 35.9 |
| DINO (ImageNet) | Self-sup. | No | 39.1 | 20.4 |
| MoCo (CC12M+YFCC) | Self-sup. | No | 36.1 | 23.0 |
| GroupViT (CC12M+YFCC) | Text | Yes | 52.3 | 22.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.