TL;DR
LeGrad is a simple yet powerful explainability method for Vision Transformers (ViTs) that generates high-fidelity heatmaps by analyzing gradients across all model layers. By capturing how each layer's attention maps contribute to a final prediction, it significantly outperforms existing methods in object localization and robustness, scaling effortlessly to models with billions of parameters.
What Problem Does This Paper Address?
While Vision Transformers (ViTs) have revolutionized computer vision, they are notoriously "black-box" models. Their reliance on self-attention mechanisms to model long-range dependencies makes it difficult to understand why a model made a specific prediction.
Existing explainability tools often fall short:
- CNN-native methods like Grad-CAM don't translate perfectly to the patch-based architecture of ViTs.
- Attention-based methods often produce "noisy" maps that highlight background pixels or "register" tokens rather than the actual object of interest.
- Complexity and Scaling: Many current techniques are computationally expensive or fail to scale to massive architectures like ViT-bigG.
The authors introduce LeGrad (Layer-wise Explainability via Gradients) to provide a transparent, robust, and computationally efficient way to visualize the decision-making process in ViTs.
Methods
LeGrad's core philosophy is that feature formation in ViTs is an iterative process happening across many layers. Instead of looking only at the final output, LeGrad computes the sensitivity of the model's prediction to the attention maps at every layer.
The process involves three main steps:
- Gradient Computation: For a specific class or text prompt, LeGrad calculates the gradient of the activation score with respect to the attention maps ($A^l$) at each layer $l$. This measures how much a small change in attention at that layer would affect the final result.
- ReLU Filtering: It applies a ReLU function to these gradients, discarding negative values. This ensures the heatmap only highlights features that positively contribute to the prediction.
- Layer Aggregation: The signals are averaged across all layers to produce a final, merged explainability map.
LeGrad is versatile; it works with standard [CLS] token architectures and more modern "Attentional Pooler" designs (like SigLIP) by slightly adapting how the activation score is calculated.
Datasets
The authors evaluated LeGrad across a diverse range of benchmarks:
- ImageNet-Segmentation: Used to test spatial fidelity in object localization.
- OpenImagesV7: A massive dataset used to evaluate "open-vocabulary" performance (localizing objects based on arbitrary text prompts).
- ADE20KSound/SpeechPrompted: Used to validate LeGrad's effectiveness in audio-visual models (localizing the source of a sound in an image).
- ImageNet-val: Used for perturbation-based tests to see if removing "important" pixels actually degrades model accuracy.
- PascalVOC: Used for detailed analysis of how gradients are distributed across layers.
Key Insights and Ideas
- The "Iterative" Nature of ViTs: One of the most important findings is that information isn't just processed at the end; it's built up. Larger models (like ViT-H/14) distribute information across more layers than smaller ones (ViT-B/16). Consequently, aggregating more layers leads to better explanations for larger models.
- Model Fingerprints: By analyzing gradient distributions, the authors found that different pre-training methods (e.g., OpenAI vs. MetaCLIP) create unique "fingerprints." Some models rely heavily on the final layer, while others peak in the middle.
- Filtering Background Noise: Raw attention maps are often distracted by background tokens. Because LeGrad uses gradients, it naturally filters out these "noisy" regions that don't actually drive the specific class prediction.
- Scaling to Billions: LeGrad was successfully applied to the ViT-bigG/14 model (2.5 billion parameters), demonstrating its readiness for the current era of "foundation models."
Key Results
- Superior Localization: On ImageNet-Segmentation, LeGrad achieved a 58.7% mIoU, significantly outperforming the popular CheferCAM (47.5%).
- Open-Vocabulary Breakthrough: In the challenging OpenImagesV7 benchmark, LeGrad reached 48.4 p-mIoU, while the next best method (TextSpan) trailed far behind at 9.44% for the same backbone.
- Audio-Visual SOTA: When paired with ImageBind, LeGrad established a new state-of-the-art for sound localization, improving mIoU by +14 points over previous methods.
- Efficiency: Despite analyzing multiple layers, LeGrad is nearly as fast as single-layer methods like Grad-CAM and much faster than LRP-based alternatives.
Limitations and Future Work
The authors noted that some models, like SigLIP, show high activations in background regions regardless of the input. To fix this, they had to implement a "dummy prompt" subtraction technique (using a generic prompt like "a photo of") to suppress irrelevant activations.
Future research could explore more sophisticated ways to weight the contributions of different layers rather than simple averaging, potentially tailoring the aggregation to the specific "fingerprint" of the model being analyzed.
Summary updated