Grad-CAM and Variants
Grad-CAM trades pixel precision for a more readable answer: which spatial regions in a convolutional feature map support this class?
For most nontechnical stakeholders, a regional heatmap is easier to interpret than a field of high-frequency gradients.
Class-weighted feature maps
Grad-CAM averages class gradients over spatial positions to get channel weights , then combines feature maps :
ReLU keeps evidence that supports the selected class.
Grad-CAM, Step by Step
Step 1 of 8
Forward-propagate the image
Run the input image through the full CNN. Every convolutional layer computes its activations until the last fully connected layer produces raw class scores (logits).
Formula
αᵏ = (1/Z) Σᵢⱼ ∂yᶜ/∂Aᵏᵢⱼ
Lc = ReLU(Σₖ αᵏ Aᵏ)
Aᵏ = feature map k, yᶜ = class score before softmax
Forward pass → class score
house
?
cat
?
car
?
tree
?
Gradients at last conv layer
roof shape
vertical edges
sky texture
αᵏ × feature map → weighted sum
α=0.72
α=0.48
α=-0.31
Σ (pre-ReLU)
ReLU → normalized heatmap
ReLU + normalize
Upscaled overlay on input
Class score (house)
—
Channels weighted
—
Negative contributions
—
Step through the full Grad-CAM pipeline. Each stage unlocks the next, so you can follow the gradient from raw class score backward to the spatial heatmap overlaid on the original image.
Layer choice matters. Late layers carry stronger semantics and lower spatial resolution. Earlier layers retain detail and may highlight generic edges.
Variants such as HiResCAM and LayerCAM change how relevance is aggregated: HiResCAM multiplies gradients and activations element-wise before summing, recovering finer spatial detail that Grad-CAM's global average discards; LayerCAM applies the same idea per-pixel and can then combine maps across multiple layers, trading some class-discriminability for higher resolution.
Compare variants on correct and incorrect predictions, then evaluate them with deletion, insertion, or domain-expert review.
Why does Grad-CAM usually use a late convolutional layer?