Subscribe
AI
5 min read

What Is Grad-CAM? The Heat Map That Shows Where an AI Looked

The orange overlay on every vision paper turns nine this year, it is still everywhere, and it is still contested. How Grad-CAM works, and what a decade of sanity checks actually found.

What Is Grad-CAM? The Heat Map That Shows Where an AI Looked

If you have looked at a deep-learning paper since 2017, you have seen the picture: a photograph of a dog, or a chest X-ray, with a translucent orange blotch glowing over the part the model allegedly looked at. That heat map is almost always a Grad-CAM output, and the method is now old enough to have a full arc: a clever trick, near-universal adoption, and a running argument about whether the maps mean anything at all.

Grad-CAM stands for Gradient-weighted Class Activation Mapping. It came out of a 2017 ICCV paper by Ramprasaath Selvaraju, Michael Cogswell, Abhishek Das, Ramakrishna Vedantam, Devi Parikh and Dhruv Batra, then at Georgia Tech and Facebook AI Research. It answers one narrow question: given a convolutional network that classified an image as "golden retriever," which pixels most influenced the score for that class?

What it grew out of

The direct predecessor was Class Activation Mapping (CAM), published at CVPR 2016 by Bolei Zhou and colleagues at MIT and Adobe. CAM exploited an architectural detail. Many image classifiers end with a global average pooling layer that compresses each feature map of the last convolutional layer into a single number, then feeds those numbers through a weighted sum to produce class scores. Those weights are sitting right there in the trained model: a channel whose number the "dog" class leans on heavily marks regions where dogs tend to be. Multiply, add up, and you get a rough spatial map.

CAM had two constraints. It only worked on networks built with that pooling-into-linear structure, and it only localized relative to the final layer. Grad-CAM's move was to replace the stored linear weights with something computable for any architecture and any layer: the gradients.

The trick in one paragraph

Run the image forward, get the score for the class you care about, and backpropagate that single score all the way to a chosen convolutional layer instead of stopping at a loss. The gradient tells you, per spatial position, how much nudging that activation would change the class score. Averaging each gradient map over its spatial positions gives one importance number per channel. Multiply each feature map by its channel number, sum the maps, clip negative values to zero, and upsample the result to the input size. The output is the heat map.

The whole recipe costs one forward pass plus one backward pass, needs no retraining, needs no special architecture, and works on any layer of the network. The paper applied it beyond classification, generating explanations for visual question answering models and image captioning models, and used it to show that adversarially perturbed images scramble the model's attention even when accuracy holds. Follow-ups tuned the weighting scheme, most visibly Grad-CAM++, which improved localization when a class appears multiple times in one image.

The lineage runs through visualization work that predates both: Zeiler and Fergus in 2013 reverse-mapped CNN activations to input space, and Ribeiro and colleagues' LIME (2016) fit local surrogate models to explain individual predictions. What made Grad-CAM the house style was the combination of zero setup and a picture a human can judge in one second, exactly the kind of artifact the field's emerging rigorous-interpretability agenda said explanation methods needed to earn trust around.

Stacked feature-map grids combine through arrows into a single heat map projected onto an abstract scene

The maps are coarse, and they can lie

Three problems have attached themselves to Grad-CAM ever since.

First, resolution. The map is born at the spatial size of a late convolutional layer, often 7x7 for a 224-pixel input, and then gets stretched to fit the photo. What you see is a smooth, vague glow, not a segmentation. That is a property of the method, not an artifact of rendering.

Second, plausibility is not faithfulness. A 2018 paper by Julius Adebayo, Justin Gilmer, Michael Muelly, Ian Goodfellow, Moritz Hardt and Been Kim, Sanity Checks for Saliency Maps, tested whether saliency methods actually depend on what they claim to. Some, including gradient-based maps, turned out nearly insensitive to model parameters and data: a randomly initialized network and a trained one could produce heat maps that looked equally convincing. A 2021 re-examination reran the model-parameter checks and kept the distinction sharp: some methods do track weights, others largely do not. The honest summary is that a heat map tells you where gradients flowed, which is not the same thing as where the decision came from.

Third, and most consequential, medicine. Saliency maps were pitched to clinicians precisely as trust aids, and the sharpest test came from that field. Rabin and colleagues benchmarked seven saliency methods on chest X-rays against radiologist ground truth, published in Nature Machine Intelligence in 2022. Grad-CAM performed best among the methods tested and still fell far short of the human benchmark. For lung lesions, the worst category, Grad-CAM's overlap with expert contours came to an mIoU of 0.027, and its region landed on the actual finding in only 21.5% of cases, numbers far below the rates for radiologists segmenting the same images. The gap was largest for pathologies that were small, numerous, or complex in shape. Notably, the maps were more reliable when the model predicted a finding with high confidence, which inverts the situation where an explanation is most wanted.

Sharp navy outline of a shape on the left beside the same location covered by a broad diffuse orange glow on the right

Why it is still everywhere

Grad-CAM survives its critiques for boring, practical reasons. It is free to run, needs no labels beyond the predicted class, and produces an artifact reviewers and users understand instantly. The pytorch-grad-cam library, which wraps Grad-CAM and dozens of successor methods, remains the standard way to introspect a convolutional classifier in PyTorch. In production vision work the maps are mostly used as debugging, not as evidence: if a "pneumonia" model's heat map sits on the corner label of the film, you have learned something real about your dataset.

The conceptual template also outlived CNNs. Interpretable-AI work on language models is doing structurally similar things with different substrates: SHAP values assign per-feature credit, logit lenses read intermediate states, and attention maps get probed with the same mixture of hope and suspicion that followed heat maps for a decade. The recurring lesson from the Grad-CAM story is the one the field keeps relearning: an explanation that a human finds convincing is a hypothesis about the model, and the 2018 sanity checks, the 2022 radiology benchmark, and the re-examinations since are what a hypothesis test looks like when it fails.

The practical rule for anyone reading a heat map today: treat it as a pointer, not a proof. It shows where the gradient was loud. Whether the model's decision actually lives there is a separate question, and the burden of showing it is on whoever put the orange on the screen.

Sources

AILLMeducational