Know Your Attention Maps: Class-specific Token Masking for Weakly Supervised Semantic Segmentation

Joëlle Hanna, Damian Borth

TL;DR

This paper introduces a novel method for weakly supervised semantic segmentation (WSSS) using Vision Transformers (ViTs). By employing multiple class-specific [CLS] tokens, a novel masking strategy, and attention head pruning, the authors generate highly accurate pseudo-segmentation masks that rival fully supervised methods, significantly reducing the need for expensive pixel-level annotations.

What Problem Does This Paper Address?

Semantic segmentation, the task of assigning a class label to every pixel in an image, is crucial for many computer vision applications. Traditionally, achieving high accuracy requires extensive pixel-level annotations, which are costly and time-consuming to obtain. Weakly supervised semantic segmentation (WSSS) aims to alleviate this burden by using less precise supervision, such as image-level labels. However, existing WSSS methods often rely on external modules like Class Activation Maps (CAMs), which suffer from coarse localization and can be complex to implement. Vision Transformers (ViTs) have shown promise, but effectively extracting class-specific information from their attention maps for segmentation remains a challenge.

Methods

The core of this work lies in adapting the Vision Transformer architecture for WSSS. Instead of a single [CLS] token, the authors introduce multiple [CLS] tokens, one for each class, to encourage class-specific representations. To ensure these tokens learn relevant information, they employ a novel random masking strategy during training. This strategy randomly masks the [CLS] tokens that don't correspond to the image's actual labels, forcing the model to learn a stronger association between the remaining [CLS] tokens and their respective classes.

Furthermore, the paper introduces attention head pruning. Recognizing that not all attention heads contribute equally, they prune redundant heads to sharpen the focus of the remaining ones, making them more interpretable and reducing noise. An additional [REG] token is also added to capture general context, preventing it from interfering with class-specific attention.

During inference, the self-attention maps from the [CLS] tokens corresponding to predicted classes are aggregated and refined to generate pseudo-segmentation masks. These masks are then used to train a standard segmentation model (like UNet).

Datasets

The authors evaluate their method on two standard benchmarks:

  • MS COCO 2014
  • Pascal VOC 2012 (augmented with SBD)

They also demonstrate its effectiveness on three domain-specific datasets, highlighting its generalization capabilities:

  • DFC2020 (remote sensing)
  • EndoTect Polyp Segmentation (medical imaging)
  • ADE20K (general scene parsing)

Key Insights and Ideas

  • Multiple [CLS] tokens are better than one for WSSS: By dedicating a [CLS] token to each class, ViTs can learn more disentangled and class-specific representations, which is crucial for segmentation.
  • Random masking is key for class assignment: Forcing [CLS] tokens to learn specific classes by randomly masking irrelevant ones significantly improves the accuracy of class assignments and the quality of pseudo-masks.
  • Attention head pruning enhances interpretability and mask quality: Removing noisy attention heads leads to sharper, more focused attention maps, resulting in smoother and more accurate pseudo-masks.
  • The [REG] token acts as a useful context anchor: This token helps to capture background or global information, preventing it from "polluting" the class-specific [CLS] token attention and improving feature delineation.
  • ViTs can achieve state-of-the-art WSSS without complex pipelines: The proposed single-stage approach demonstrates that leveraging ViT's inherent attention mechanisms can be highly effective for WSSS, outperforming many multi-stage methods.

Key Results

  • Pseudo-mask quality: The method achieves a validation mIoU of 73.7% on Pascal VOC, slightly outperforming the previous best single-stage method. Qualitative results show pseudo-masks closely matching ground truth.
  • Final segmentation performance: The method achieves competitive results on standard benchmarks, including the highest VOC test mIoU (73.5%) among the evaluated methods.
  • Specialized datasets: The approach achieves state-of-the-art results on DFC2020, Endotect, and ADE20K, even surpassing some fully supervised methods, demonstrating robustness across diverse and challenging domains.
  • Reduced need for labels: The paper shows that their method significantly reduces the dependency on fine-grained labeled data.

Limitations and Future Work

  • Scalability concerns: As the number of classes increases, so does the number of [CLS] tokens, leading to increased computational complexity and memory requirements.
  • Future work: The authors suggest exploring dynamic token assignment strategies to reduce unnecessary computations while maintaining segmentation accuracy. Optimizing parameter efficiency remains an open challenge.

Summary updated

BibTeX
@inproceedings{hanna2025know,
  author = {Joëlle Hanna and Damian Borth},
  title = {{Know Your Attention Maps: Class-specific Token Masking for Weakly Supervised Semantic Segmentation}},
  booktitle = {IEEE/CVF International Conference on Computer Vision},
  year = {2025},
}
Figure