Grad-CAM

Also known as: Gradient-weighted class activation mapping

On this page 7

Grad-CAM, short for gradient-weighted class activation mapping, is a post-hoc explanation technique that produces a coarse heat map of the most influential image regions behind a convolutional neural network’s prediction for a chosen class. In AI ethics and transparency work, it is one of the most widely used tools for checking whether a vision model looks at the right evidence or relies on shortcuts such as watermarks, backgrounds or hospital markers.

The method was introduced in 2017 as a generalization of the earlier class activation mapping approach. Its key advantage is that it requires no change to the network architecture and no retraining: it only needs the gradients and feature maps that a trained model already computes.

How Grad-CAM computes a class activation map

Grad-CAM works by weighting late convolutional feature maps by how strongly they affect the target class score. The last convolutional layer is usually chosen because it keeps spatial layout while encoding high-level, class-relevant concepts.

  1. Run a forward pass and take the raw class score before the softmax for the class of interest.
  2. Backpropagate that score to the chosen layer to obtain the gradient for every feature map.
  3. Average each gradient map over its spatial positions to get one importance weight per channel.
  4. Compute a weighted sum of the feature maps and apply a ReLU to keep only positive evidence.
  5. Upsample the small map to the input size and overlay it on the image as a heat map.

The ReLU step matters: it keeps regions that increase the score for the class and discards those that argue against it. Because the final convolutional grid is often only 7 by 7 or 14 by 14 cells, the resulting map is coarse and low resolution, which is a deliberate trade-off between localization and semantic meaning.

The table below shows how the choice of layer changes the explanation.

Target layerMap resolutionWhat the map reflects
Final convolutional layerLow, often 7 by 7Class-specific, semantically meaningful regions
Middle convolutional layerMediumParts and textures, weaker class specificity
Early convolutional layerHighEdges and colors, little class meaning
Effect of the target layer

Variants and extensions of the method

Several variants address the coarseness and the weighting rule of the original method. They share the same idea of mapping class evidence back to spatial regions but differ in how channel weights are computed.

VariantMain changeTypical benefit
Guided Grad-CAMMultiplies the map with guided backpropagationSharper, pixel-level detail
Grad-CAM++Uses higher-order gradient weightingBetter coverage of multiple objects
Score-CAMWeights channels by score change, not gradientsLess sensitive to gradient noise
Layer-CAMUses element-wise gradient weights per positionFiner maps from earlier layers
Eigen-CAMUses principal components of activationsClass-agnostic overview without gradients
Common Grad-CAM variants

Grad-CAM was designed for convolutional networks, yet adapted versions are applied to vision transformers by reshaping token activations into a grid. Results on transformers are less stable, and attention-based methods are often reported alongside them.

Grad-CAM compared with other explanation methods

Grad-CAM belongs to the family of saliency map methods, but it differs from model-agnostic tools such as SHAP and LIME and from path-based methods such as integrated gradients. The choice depends on model access, required resolution and computational budget.

MethodModel accessResolutionCost per explanation
Grad-CAMGradients and activationsCoarse region mapOne forward and backward pass
Vanilla gradient saliencyGradientsPixel level, noisyOne backward pass
Integrated gradientsGradientsPixel levelTens to hundreds of passes
LIMEBlack-box predictions onlySuperpixel regionsHundreds of perturbed queries
SHAPBlack-box or model-specificFeature or region levelOften the highest
Explanation methods for image models

In practice, Grad-CAM is valued for being fast, class-discriminative and easy to read. It is less suitable when a decision depends on fine detail, such as a hairline crack or a tiny lesion, where pixel-level attribution performs better.

Uses in fairness, auditing and accountability

In ethical review, Grad-CAM is mainly a tool for detecting spurious correlations and shortcut learning. When the heat map consistently highlights a ruler, a text label or a background rather than the object itself, the model has likely learned a dataset artifact instead of the intended concept.

  • AI audits use it to inspect whether predictions rely on protected attributes visible in images, such as skin tone or clothing.
  • Bias investigations compare heat maps across demographic groups to reveal measurement or representation bias.
  • Model debugging uses it before deployment to catch data leakage from scanner markings or file watermarks.
  • Human review in clinical or safety settings uses it as a cue, not as proof, when an expert checks a prediction.

The decision table below shows when Grad-CAM is an appropriate first step and when another method should be added.

SituationRecommendationReason
Screening for shortcut learningUse Grad-CAM across many samplesFast and reveals consistent artifacts
Explaining one high-stakes decisionCombine with a second methodSingle maps can mislead
Fine-grained defect or lesionPrefer pixel-level attributionGrad-CAM is too coarse
No access to model internalsUse LIME or SHAP insteadGrad-CAM needs gradients
When to rely on Grad-CAM

Limitations and common misreadings

The most important warning is that a plausible heat map is not proof that a model is fair or correct. Grad-CAM shows where evidence was located, not why the model treated it as evidence or whether the reasoning generalizes.

  • Faithfulness is limited: sanity-check studies show some saliency maps change little when model weights are randomized, so results must be tested.
  • Coarse maps blur nearby objects, which can wrongly suggest that a protected attribute was used.
  • Confirmation bias leads reviewers to accept maps that match their expectations and to ignore unexpected ones.
  • Cherry-picked examples in reports give an unrepresentative picture of model behavior.
  • Gradient saturation can produce weak or empty maps even for confident predictions.

Responsible use therefore means reviewing many samples systematically, running randomization sanity checks and documenting the layer, preprocessing and class used, so that the explanation itself remains auditable and contestable.

Put simply

Grad-CAM is a way to ask an image recognition system, where were you looking when you decided. It paints a colored glow over the parts of a picture that pushed the system toward its answer.

Say a system labels a photo as a dog. If the glow sits on the dog, that is reassuring. If it sits on the grass or a logo in the corner, the system may be right for the wrong reason. People then know they must fix the training data before trusting it.

In practice

A hospital research team trained a network to flag pneumonia on chest X-rays and reached high accuracy on its validation set. Before a pilot, an internal review group ran Grad-CAM on 500 randomly selected test images rather than on a few favorable cases.

On many positive predictions, the heat map concentrated on text markers in the image corner instead of the lungs. The markers came from portable scanners used mostly for bedside patients, who were more often seriously ill. The model had learned that the scanner type predicted the diagnosis.

The team cropped and masked the markers, rebalanced images by scanner and retrained. Accuracy dropped slightly, but the new heat maps focused on lung regions, and performance held up on data from a second hospital, which the original model had failed.