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.
| Step | Operation | Output |
|---|---|---|
| Forward pass | Run the image through the network | Class score and feature maps |
| Backward pass | Differentiate the class score | Gradients for each feature map |
| Pixel coefficients | Derive weights from gradient powers | Per-location weighting factors |
| Channel weights | Sum weighted positive gradients | One importance value per channel |
| Combination | Weighted sum of maps, then ReLU | Low-resolution heatmap |
| Upsampling | Resize to input dimensions | Overlay on the original image |
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.
| Method | Signal used | Cost per explanation | Typical strength |
|---|---|---|---|
| Class activation mapping | Weights of a global pooling layer | One forward pass | Simple, needs a specific architecture |
| Grad-CAM | Averaged gradients | One backward pass | Fast, works on most CNNs |
| Grad-CAM++ | Weighted positive gradients | One backward pass | Better multi-object coverage |
| Score-CAM | Score changes from masked inputs | One pass per channel | No gradients, often cleaner maps |
| Guided backpropagation | Modified backward ReLU signals | One backward pass | Sharp edges, weak class focus |
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.
| Situation | Recommended choice | Reason |
|---|---|---|
| Standard CNN classifier | Last convolutional block | Best balance of semantics and location |
| Small objects in large images | A slightly earlier block | Higher spatial resolution |
| Several objects of one class | Grad-CAM++ over Grad-CAM | Weighting captures every instance |
| Explaining a wrong prediction | Target the predicted class | Shows what misled the model |
| Vision transformer | Reshaped token outputs of a late block | Requires adapting the method |
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.