jacobgil/pytorch-grad-cam
Advanced AI Explainability for computer vision. Support for CNNs, Vision Transformers, Classification, Object detection, Segmentation, Image similarity and more.
What it solves
This library provides a comprehensive collection of Pixel Attribution methods for computer vision, allowing developers and researchers to diagnose model predictions by visualizing which parts of an image the AI model is focusing on. It helps turn "black box" vision models into explainable AI (XAI) by highlighting the regions that contribute most to a specific prediction.
How it works
The package implements various Class Activation Mapping (CAM) methods that analyze the activations and gradients of a PyTorch model's target layers. It supports a wide range of techniques, including gradient-based methods (like GradCAM and GradCAM++), gradient-free methods (like AblationCAM and ScoreCAM), and PCA-based methods (like EigenCAM). To handle different architectures, it uses "reshape transforms" to convert activations into spatial images and "model targets" to define exactly what the model output should be explained.
Who it’s for
- AI Researchers: Those developing new explainability methods or benchmarking existing ones.
- ML Engineers: Developers needing to diagnose model behavior in production or during development.
- Computer Vision Practitioners: Anyone working with CNNs or Vision Transformers (ViT) across tasks like classification, object detection, and semantic segmentation.
Highlights
- Broad Method Support: Includes a vast array of state-of-the-art methods such as GradCAM, HiResCAM, FullGrad, and ShapleyCAM.
- Architecture Agnostic: Works with common CNNs and Vision Transformers (e.g., ResNet, ViT, Swin Transformer).
- Task Versatility: Supports classification, object detection, semantic segmentation, and embedding similarity.
- Evaluation Metrics: Includes built-in metrics (like ROAD and ARCC) to quantitatively check if explanations can be trusted.
- SESS Wrapper: A meta-method that uses sliding windows and multiple scales to make explanations robust to scale variance and distractors.
- Smoothing Tools: Provides test-time augmentation and eigen-smoothing to reduce noise in the visualizations.
Related
- Project
- Project
- Project
- Project
- Project