6.3.3 · D3Interpretability & Explainability

Worked examples — Saliency maps and Grad-CAM

2,532 words12 min readBack to topic

This page is the hands-on drill room for Saliency maps and Grad-CAM. The parent note built the ideas; here we grind through every case a saliency or Grad-CAM computation can throw at you — positive gradients, negative gradients, zero gradients, dead feature maps, degenerate images, and one exam-style trap. Nothing new is assumed: every symbol used below is re-earned here.


The scenario matrix

Every worked example below is tagged with the cell of this matrix it covers. Together they touch every cell.

Cell What makes it different Where it bites
A. Positive gradient pixel/feature pushes score up normal saliency pixel
B. Negative gradient pixel pushes score down why we take absolute value
C. Sign-mix across channels R, G, B disagree aggregation choice matters
D. Zero gradient (flat) model insensitive here dead / saturated region
E. Degenerate input constant / blank image gradient can vanish everywhere
F. Grad-CAM positive weight feature map helps class bright region
G. Grad-CAM negative weight feature map hurts class ReLU decision
H. Softmax-vs-logit trap coupling across classes the classic pitfall
I. Real-world word problem "is the model cheating?" debugging use-case
J. Exam twist limiting / normalization edge full-page all-zero map

Group 1 — Saliency at the pixel level

The figure below plots exactly this example. The cyan bars are the raw signed gradients ; the amber bars are the saliencies . Follow the amber arrow: it points at pixel , whose bar is tallest after taking the absolute value even though its cyan (signed) bar dips below the white zero line. That single crossing is the whole lesson — sign lives on the cyan bars, importance lives on the amber ones.

Figure — Saliency maps and Grad-CAM



Group 2 — Grad-CAM at the feature-map level

The three panels below walk this computation left to right. The left two panels are the raw feature maps and with their pooled weights and printed in the titles; the right panel is the weighted sum , which comes out uniformly in every cell. Notice how 's bright diagonal and 's bright anti-diagonal interlock so that once each is scaled and added, no cell is left dark — that is why the final heatmap is flat.

Figure — Saliency maps and Grad-CAM

The two panels below are the before and after of Step 3. The left panel is the pre-ReLU sum, where the top-right and bottom-left cells sit at (rendered cool/blue). The right panel is post-ReLU, where those two negative cells have been clipped to , leaving only the warm diagonal at . Reading left→right you literally watch ReLU erase the "arguments against dog" and keep the localization clean.

Figure — Saliency maps and Grad-CAM

Group 3 — The softmax trap, a word problem, and an exam twist


Recall Self-test

Positive gradient vs negative gradient : which pixel is more salient? ::: The pixel; saliency uses , so . Max-abs vs L2 for ? ::: Max , L2 ; L2 is always max. Dead ReLU (input ) saliency? ::: Zero everywhere — a black map, and that is correct. Grad-CAM with on map : what does ReLU do? ::: Clips the negative cells to , keeping only positive-evidence regions. Why logits not softmax for saliency? ::: Softmax couples classes; another class's logit can move even when is fixed. All-negative → normalizing gives : report what? ::: A blank map — no positive evidence — never a fabricated pattern.

Prerequisites worth a look: Convolutional Neural Networks (feature maps), Attention mechanisms (a different "where is the model looking?" tool), and robustness contrasts in Adversarial examples.