CaFT: Clustering and Filter on Tokens of Transformer for Weakly Supervised Object Localization

Ming Li · DOI

Abstract

Weakly supervised object localization (WSOL) is a challenging task to localize the object by only category labels. However, there is contradiction between classification and localization because accurate classification networks tend to pay attention to discriminative regions of objects rather than the entirety. We propose this discrimination is caused by handcrafted threshold choosing in CAM-based methods. Therefore, we propose Clustering and Filter of Tokens (CaFT) with a Vision Transformer (ViT) backbone to solve this problem. CaFT first sends the patch tokens of the image split to ViT and clusters the output tokens to generate an initial mask of the object. Secondly, CaFT considers the initial mask as pseudo-labels to train a shallow convolution head (Attention Filter, AtF) following the backbone to directly extract the mask from tokens. Then, CaFT splits the image into parts, outputs masks respectively, and merges them into one refined mask. Finally, a new AtF is trained on the refined masks and used to predict the box of the object. Experiments verify that CaFT outperforms previous work and achieves 97.55% and 69.86% localization accuracy with ground-truth class on CUB-200 and ImageNet-1K respectively.

Introduction

Weakly Supervised Object Localization (WSOL) aims to identify the precise location of an object within an image using only image-level category labels during training. Traditionally, Class Activation Mapping (CAM) has been the dominant technique. However, CAM-based methods often fall into the "discriminative trap," where the network focuses only on the most distinctive parts of an object (like a bird's beak) to minimize classification error, failing to capture the object's full extent. Furthermore, converting these heatmaps into bounding boxes typically requires manually tuned thresholds, which lack robustness across diverse datasets.

Methodology: Clustering and Filter on Tokens (CaFT)

CaFT shifts the paradigm from thresholding heatmaps to clustering tokens within a Vision Transformer (ViT) architecture. The pipeline consists of several key stages:

  1. Token Generation and Clustering: The input image is split into patches and processed by a ViT backbone. The resulting output tokens are clustered using k-means ($k=3$).
  2. Foreground Identification: A critical observation is that the special [CLS] token, used for classification, consistently clusters with tokens representing the foreground object. This provides an automatic, data-driven way to identify the object mask without manual thresholds.
  3. Attention Filter (AtF): To refine the noisy initial clusters, CaFT introduces a shallow convolutional head called the Attention Filter. This head is trained using the initial cluster masks as pseudo-labels, learning to produce a denoised, continuous mask.
  4. Recursive Refinement: The process is applied hierarchically. The image is split into parts to generate local masks, which are then merged into a high-resolution refined mask. This refined mask trains a final AtF head dedicated to bounding box prediction.
The CaFT architecture overview, showing the flow from ViT tokens to clustering and the Attention Filter.

Why Transformers?

The success of CaFT is rooted in the inherent properties of Vision Transformers compared to traditional CNNs. In CNNs, features are often locally correlated, leading to "smeared" activation maps that struggle to separate foreground from background clearly. In contrast, ViT tokens benefit from global self-attention, resulting in higher variance between object and background clusters.

Comparison of clustering results and similarity matrices between CNN and ViT, highlighting the clearer separation in ViT tokens.

As shown in the comparison above, ViT tokens produce much sharper clustering results and a more structured similarity matrix, making the [CLS] token a highly effective anchor for the foreground.

Experimental Results

The authors evaluated CaFT on the CUB-200-2011 and ImageNet-1K benchmarks. Due to the high computational cost of running k-means on millions of images, the authors used a mini-set of 10,000 images (10 per class) to train the AtF for ImageNet.

  • CUB-200: CaFT achieved a state-of-the-art (SOTA) localization accuracy of 97.55% (Gt-Known Loc), significantly outperforming previous methods like SPOL (96.46%) and TS-CAM (86.6%).
  • ImageNet-1K: CaFT achieved 69.86% Gt-Known Loc, surpassing the previous best of 69.02%.
  • Robustness: The method demonstrates superior stability across various Intersection over Union (IoU) thresholds, proving that the clustering approach is more reliable than traditional heatmap thresholding.

Conclusion

CaFT provides a fresh perspective on WSOL by leveraging the structural properties of Transformer tokens. By replacing brittle thresholds with k-means clustering and a learnable Attention Filter, it effectively captures the full extent of objects. While the multi-stage training presents complexity, the approach sets new performance benchmarks and opens new doors for unsupervised object discovery.

Summary updated

BibTeX
@misc{li2022caft,
  author = {Ming Li},
  title = {{CaFT: Clustering and Filter on Tokens of Transformer for Weakly Supervised Object Localization}},
  year = {2022},
  eprint = {2201.00475},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2201.00475},
}
Figure