pytorch-grad-cam is a PyTorch library for producing pixel-attribution visualizations that help diagnose computer vision model predictions. It provides class activation map methods and related tools for evaluating and refining explanations.
Project overview
Its combination of multiple pixel-attribution methods, explanation-trust metrics, batch support, smoothing, and adaptation hooks makes it relevant for teams investigating how PyTorch computer vision models reach their outputs.
Project type
Image & Vision · Evaluation & Observability
Deployment
Refer to project documentation
License
MIT
Best for
Developers, researchers, and AI engineers who need to inspect and diagnose predictions from PyTorch computer vision models.
Key capabilities
Computes class activation maps with methods including GradCAM, HiResCAM, ScoreCAM, and EigenCAM for various computer vision tasks.
Visualizes important pixels to diagnose model predictions during development or in production.
Includes metrics for assessing whether explanations can be trusted and tuning them for performance, including Remove and Debias.
Supports batches of images across all methods.
Provides test-time augmentation and eigen smoothing to reduce noise and improve CAM appearance.
Supports non-standard architectures such as Vision Transformers and non-classification tasks through reshape transforms and custom model targets.
Getting started
Install with `pip install grad-cam`, then run `python cam.py --image-path <path_to_image> --method <method>`.
Evidence and sources
README: `pip install grad-cam`
README: This is a package with state of the art methods for Explainable AI for computer vision. This can be used for diagnosing model predictions, either in production or while developing…
README: Includes metrics for checking if you can trust the explanations, and tuning them for best performance.
GitHub project description: Advanced AI Explainability for computer vision. Support for CNNs, Vision Transformers, Classification, Object detection, Segmentation, Image similarity and more.
README: model = resnet50(weights=ResNet50_Weights.DEFAULT) target_layers = [model.layer4[-1]] input_tensor = # Create an input tensor image for your model..