Grad-CAM++

On this page 6

Grad-CAM++ is a gradient-based class activation mapping method that produces a coarse heatmap showing which regions of an input image most influenced a convolutional neural network’s prediction for a chosen class. In Explainable AI, it is a widely used post-hoc, model-specific saliency technique that generalizes Grad-CAM by weighting positive gradients at each spatial location instead of averaging them uniformly.

The method was introduced in 2018 to address two weaknesses of Grad-CAM: poor localization when several instances of the same class appear in one image, and heatmaps that cover only the most discriminative part of an object. Grad-CAM++ typically yields more complete object coverage while keeping the low cost of a single backward pass.

How Grad-CAM++ computes its heatmap

Grad-CAM++ builds the heatmap as a weighted sum of feature maps from a chosen convolutional layer, usually the last one. Each feature map receives one channel weight, and the sum is passed through a ReLU so that only regions with a positive influence on the class score remain.

The difference from Grad-CAM lies in how the channel weights are computed. Grad-CAM averages all gradients of the class score over the feature map. Grad-CAM++ instead computes pixel-wise weighting coefficients from second-order and third-order derivatives, then sums only the positive partial derivatives weighted by those coefficients. In practice, the class score is passed through an exponential function, which lets the higher-order derivatives be expressed in closed form using first-order gradients alone.

The process follows a fixed sequence of steps, summarized in the table below.

StepOperationOutput
Forward passRun the image through the networkClass score and feature maps
Backward passDifferentiate the class scoreGradients for each feature map
Pixel coefficientsDerive weights from gradient powersPer-location weighting factors
Channel weightsSum weighted positive gradientsOne importance value per channel
CombinationWeighted sum of maps, then ReLULow-resolution heatmap
UpsamplingResize to input dimensionsOverlay on the original image
Steps of the Grad-CAM++ computation

Because the heatmap comes from a late convolutional layer, its native resolution is coarse, often 7 by 7 or 14 by 14 cells for common image classifiers. Upsampling smooths the result but cannot add detail that the layer does not encode.

Grad-CAM++ compared with other saliency methods

Grad-CAM++ belongs to the class activation mapping family, which trades pixel-level detail for class-discriminative, object-level localization. The comparison below places it among its closest neighbors.

MethodSignal usedCost per explanationTypical strength
Class activation mappingWeights of a global pooling layerOne forward passSimple, needs a specific architecture
Grad-CAMAveraged gradientsOne backward passFast, works on most CNNs
Grad-CAM++Weighted positive gradientsOne backward passBetter multi-object coverage
Score-CAMScore changes from masked inputsOne pass per channelNo gradients, often cleaner maps
Guided backpropagationModified backward ReLU signalsOne backward passSharp edges, weak class focus
Grad-CAM++ and related saliency techniques

Grad-CAM++ can be combined with guided backpropagation into Guided Grad-CAM++, which multiplies the coarse heatmap with a fine-grained gradient image. The result shows both where the evidence lies and which edges and textures contributed, although guided backpropagation itself has known faithfulness problems.

Grad-CAM++ also differs from perturbation-based methods such as occlusion sensitivity and from attribution methods such as Integrated Gradients or SHAP. Those approaches assign importance at the pixel or superpixel level and can satisfy formal axioms, but they require many forward passes. Grad-CAM++ is far cheaper, which makes it practical for interactive debugging and large-scale audits where thousands of images must be explained quickly.

Library support is mature. Open-source packages for PyTorch, such as Captum and the widely used pytorch-grad-cam library, implement Grad-CAM++ alongside Grad-CAM and Score-CAM, so teams can compare several methods on the same image with only a few lines of configuration. Comparing methods side by side is a useful habit, because agreement between independent techniques raises confidence in the explanation.

Choosing the target layer and class

The target layer is the most consequential configuration choice. Deeper layers carry more semantic, class-specific information but less spatial detail; earlier layers preserve detail but respond to generic edges and textures rather than the class.

SituationRecommended choiceReason
Standard CNN classifierLast convolutional blockBest balance of semantics and location
Small objects in large imagesA slightly earlier blockHigher spatial resolution
Several objects of one classGrad-CAM++ over Grad-CAMWeighting captures every instance
Explaining a wrong predictionTarget the predicted classShows what misled the model
Vision transformerReshaped token outputs of a late blockRequires adapting the method
Practical configuration choices

The target class should be chosen deliberately. Explaining the predicted class shows what drove the decision, while explaining a competing class can reveal contrastive evidence, such as why the model rejected an alternative label.

Limitations and faithfulness concerns

Grad-CAM++ heatmaps are plausible-looking but not guaranteed to be faithful to the model’s actual reasoning. Sanity-check studies have shown that several gradient-based saliency methods change little when model weights are randomized, so a convincing image alone is not proof of correct behavior.

  • Coarse resolution hides fine detail and can blur adjacent objects together.
  • Gradient saturation in confident predictions can weaken or distort the signal.
  • The ReLU step discards negative evidence, so the map shows support only, never counter-evidence.
  • Layer choice changes the picture, which makes results hard to compare across studies.
  • Architecture dependence limits direct use outside convolutional networks.

Responsible use pairs Grad-CAM++ with quantitative checks such as deletion and insertion curves, which measure how quickly the class score drops when the highlighted pixels are removed. A heatmap that passes these tests deserves considerably more trust than one judged by visual appeal.

In everyday language

Grad-CAM++ is like a highlighter for image recognition. An AI system looks at a photo and decides what it shows. The method colors the parts of the photo that mattered most for that decision.

Older versions often marked only one spot. Grad-CAM++ is better at marking every object that counts, such as all three dogs in a picture. The key point is caution: the colors show where the model looked, but not always why.

Seen in the real world

A hospital research team trains a convolutional network to flag pneumonia on chest X-rays. Validation accuracy is high, but before a clinical pilot, radiologists review Grad-CAM++ heatmaps for 500 positive predictions.

Most heatmaps highlight the lung fields as expected. However, about one in ten concentrates on a hospital marker in the image corner, a text label used mainly by one ward with sicker patients. The team realizes the model has learned a shortcut from the scanner labels, crops the markers from all images and retrains. The new model loses a little validation accuracy but generalizes better to X-rays from a second hospital, which was the real goal.