Abstract
Vision Transformer (ViT) has become a cornerstone of modern computer vision, yet its unique architecture presents significant challenges for interpretability. Traditional visualization methods designed for CNNs often fail to provide accurate localization in ViT-based models. In this work, we propose Attention Guided CAM (AG-CAM), a novel visualization method that provides high-level semantic explanations for ViT decisions. By selectively aggregating gradients through skip connections and guiding them with sigmoid-normalized self-attention scores, AG-CAM effectively captures the full spatial extent of target objects. Our method outperforms existing explainability techniques in weakly-supervised localization tasks and demonstrates superior faithfulness to the model's decision-making process, as evidenced by perturbation tests.
Introduction
Vision Transformers (ViTs) have fundamentally shifted the landscape of computer vision, often surpassing traditional Convolutional Neural Networks (CNNs) in complex recognition tasks. However, as these models are deployed in sensitive areas like medical imaging or autonomous driving, the need for "explainability"—understanding why a model made a specific prediction—becomes paramount.
While tools like Grad-CAM have long served as the standard for visualizing CNNs, they do not translate effectively to the Transformer architecture. ViTs rely on self-attention mechanisms and a global [class] token, which creates a different flow of information compared to the hierarchical spatial features of CNNs. This paper introduces AG-CAM to bridge this gap, providing a robust method for generating class-specific visual explanations.
The Interpretability Gap in ViTs
Existing visualization methods for ViTs face two primary hurdles:
- Non-Class Specificity: Early methods like Attention Rollout visualize general attention patterns but cannot distinguish between different classes. For instance, in an image containing both a dog and a cat, these methods struggle to show the specific features used to identify the dog versus the cat.
- The Peak Intensity Problem: Transformers utilize the
softmaxfunction within their self-attention layers. While effective for training,softmaxtends to produce "peaky" distributions, focusing on very small, high-contrast areas (e.g., a single eye or a sharp edge). This results in heatmaps that appear as scattered dots rather than a cohesive highlight of the entire object.
Methodology: Attention Guided CAM (AG-CAM)
AG-CAM addresses these issues through two primary technical innovations designed to recover spatial context and improve localization.
Gradient Aggregation via Skip Connections
In a ViT, spatial information is often preserved through skip connections (residual paths) rather than the attention matrices themselves. AG-CAM selectively collects gradients propagated from the classification output back through the encoder blocks, specifically focusing on these skip connections. This approach ensures that the resulting heatmap retains the spatial integrity of the input image as it moves through the deep layers of the network.
Sigmoid Normalization
The authors identify softmax as a visualization bottleneck that suppresses medium-level correlations vital for a full explanation. AG-CAM replaces the standard normalization with a sigmoid function during the visualization process. This "recovers" the broader context of the object, allowing the heatmap to expand from isolated peaks to cover the entire body of the target class.
Experimental Evaluation
The researchers evaluated AG-CAM against leading explainability methods, including Attention Rollout and Layer-wise Relevance Propagation (LRP) variants, across three major benchmarks: ImageNet ILSVRC 2012, Pascal VOC 2012, and CUB 200.
Key Results
- Superior Localization: On the ImageNet dataset, AG-CAM achieved an Intersection over Union (IoU) of 52.12%, nearly doubling the performance of the LRP-based method (20.29%).
- Enhanced Recall: AG-CAM demonstrated a significantly higher recall (62.76% on ImageNet), proving its ability to capture the full instance of an object rather than just a fragment.
- Model Faithfulness: To ensure the heatmaps truly reflect the model's logic, the authors conducted "pixel perturbation" tests. By removing pixels identified as important and measuring the drop in model confidence, AG-CAM achieved the highest ABPC score (0.3691), confirming that the highlighted regions are indeed the most influential for the classification.
Discussion and Future Work
AG-CAM represents a significant step forward in making Vision Transformers more transparent. By providing elaborate, high-level semantic explanations using only class labels, it makes ViTs more viable for weakly-supervised object localization (WSOL) tasks.
While the current study focuses on the base ViT architecture, future research could expand this method to more recent variants like Swin Transformers or DeiT. Additionally, while gradient-based methods involve more computation than simple attention averaging, the gains in localization accuracy and faithfulness provide a compelling trade-off for applications where trust and precision are critical.
Summary updated