Class activation mapping
Class activation mapping methods are explainable AI (XAI) techniques used to visualize the regions of an input image that are the most relevant for a particular task, especially image classification, in convolutional neural networks (CNNs).[src] These methods generate heatmaps by weighting the feature maps from a convolutional layer according to their relevance to the target class.[src] CNNs are designed to process spatially structured data, such as images, exploiting a series of convolution, non-linear activation, and pooling operations to extract relevant features contained in the so-called feature maps from input data.[src] CNNs have proven to be highly effective in a variety of computer vision and image processing tasks.[src] Despite their strengths, CNNs (and deep-learning models more broadly) are described as black boxes due to their complex and non-transparent internal layers of representation.[src] The need to interpret decision-making processes gave birth to XAI techniques.[src] Class-activation mapping methods were originally developed for class-discriminative scenarios to visualize which parts of the input image influenced the classification decision, namely to visually highlight the regions of those feature maps that contribute most strongly to the prediction of a given class.…[src]
Class activation mapping methods are explainable AI (XAI) techniques used to visualize the regions of an input image that are the most relevant for a particular task, especially image classification, in convolutional neural networks (CNNs).[src] These methods generate heatmaps by weighting the feature maps from a convolutional layer according to their relevance to the target class.[src] CNNs are designed to process spatially structured data, such as images, exploiting a series of convolution, non-linear activation, and pooling operations to extract relevant features contained in the so-called feature maps from input data.[src] CNNs have proven to be highly effective in a variety of computer vision and image processing tasks.[src] Despite their strengths, CNNs (and deep-learning models more broadly) are described as black boxes due to their complex and non-transparent internal layers of representation.[src] The need to interpret decision-making processes gave birth to XAI techniques.[src] Class-activation mapping methods were originally developed for class-discriminative scenarios to visualize which parts of the input image influenced the classification decision, namely to visually highlight the regions of those feature maps that contribute most strongly to the prediction of a given class.[src] More advanced versions of these methods are not limited to image classification tasks, but have been extended also to several vision-related tasks, such as object detection, image captioning, visual question answering, image segmentation, and medical image interpretation.[src] Image-specific class saliency visualization method provides a visual explanation by highlighting the most relevant pixels in an image for predicting a certain class C of interest.[src] This is done by computing the gradient of the class score with respect to the input image, I_0, w = \left.[src] \frac{\partial S_C}{\partial I} \right|_{I_0} approximating the model locally (around I_0 ) as linear, using a first-order Taylor expansion: S_C(I) \approx w_C^T I + b .[src] The magnitude of w_C , the gradient, indicates the importance of the pixels: larger gradients suggest greater influence on the prediction.[src] Once the gradient is known, the saliency map is defined as the maximum absolute gradient across the color channels: M_{ij} = max_C \left| \frac{\partial S_C}{\partial I_{ij}^C} \right| resulting in a saliency map (i.e.[src] heatmap).[src] F^k = \frac{1}{mn} \sum_{i=1}^m\sum_{j=1}^n A^k_{ij} with A^k = \begin{bmatrix} A^k_{11} & A^k_{12} & \cdots & A^k_{1n} \\ A^k_{21} & A^k_{22} & \cdots & A^k_{2n} \\ \vdots & \vdots & \ddots & \vdots \\ A^k_{m1} & A^k_{m2} & \cdots & A^k_{mn} \end{bmatrix} L_{CAM}^{C}(x,y) = ReLU(\sum_k w_k^C A_k(x,y)) namely, A_k(x,y) is the activation of node k in the target layer of the model, and w_k^C is the class-specific weight, for the channel k, in the linear classifier layer.[src] ====Advantages and drawbacks==== The use of the GAP layer represents an example of an interpretability by design (IBD) approach.[src] IBD refers to a technique which uses the model's own architecture to help explain its predictions.[src] The main drawback of CAM is that it is highly model-specific, being applicable to CNN architectures whose layer before the softmax one is a GAP.[src] Since the approach relies on the post-GAP weights for the overall evaluation, the method can't be applied to intermediate layers.[src] The choice of dealing with an IBD approach restricts the possibility to generalize the model architecture.[src] Moreover, IBD methods often require re-training of the model.[src] \alpha_k^C = \frac{1}{uv} \sum_{i} \sum_{j} \frac{\partial{y^C}}{\partial{A^k}(i,j)} So, to account for the total number of feature maps, each of them is multiplied by its weight (via dot-product) and element-wise summation: \sum_k \alpha_k^C A^k It can be observed that, due to the intrinsic nature of the gradient operation, some elements of the weighted feature map will have negative values; so, since only elements that have increased the logit of the predicted class are of interest, a ReLU activation function is applied: L_{Grad-CAM}^C(x,y) = ReLU(\sum_k \alpha_k^C A^k(x,y)) Lastly, the output heatmap image dimensions are upsampled to the original image size to match the input dimensions.[src] L^C_{Grad-CAM++}(x,y) = \sum_k w_k^C A_k(x, y) in which the coefficient w_k^C is defined as: w_k^C = \sum_{i,j} \alpha_k^C(i, j)\times ReLU(\frac{\partial y^C}{\partial A_k(i,j)}) with A^k(x,y) , the activation of node k in the target layer of the model at position (x,y); y^C the logit score for class C; and \alpha_k^C(i,j) being: \alpha_k^C(i,j) = \frac{\frac{\partial^2 y^C}{\partial (A_k(i,j))^2}}{2\times\frac{\partial^2 y^C}{\partial (A_k(i,j))^2}+\sum_{a,b}A_k(a,b)\times\frac{\partial^3 y^C}{\partial (A_k(i,j))^3}} While addressing some Grad-CAM problems, Grad-CAM++ method still relies on gradients, and it only improves the underlying math.[src] It is, however, still based on the idea of assigning a direct and valid relationship between gradient and importance.[src] Notation: (a,b) indexes all pixel positions in the feature‐map, exactly as (i,j) does, but for the summation in the denominator.[src] Multiplies the original input image by the mask, defining a masked image X'_k = M_k \odot X ( \odot is the element-wise multiplication); Gets a confidence score (a softmax probability is the output value after the softmax operation; the logit is the value before the softmax) for the masked images X'_k , by feeding it into the CNN (either the soft-max probability or the raw logit can be used; both yield similar results in practice); Considers that confidence score as the weight w_k^c for the feature map A_k .[src] These operations replace the gradient calculations with the actual model outputs, building more accurate heatmaps.[src] Mathematically, the localization map is defined as: L_{Score-CAM}^C(x,y) = ReLU(\sum_k w_k^c A_k(x,y)) and the coefficient w_k^C s: w_k^C = softmax_{k}(y^C(X'_k)) = \frac{exp(y^C(X'_k))}{\sum_m exp(y^C(X'_m))} where A_k(x,y) is the activation of channel k at location (x,y), y^C(X) is the logit for class C for an input X, and M_k is the mask, defined as: M_k(x,y) = \frac{U(A_k)(x,y)-min_{x,y} U(A_m)}{max_{x,y} U(A_k) - min_{x,y} U(A_k)} with U as the upsampling operation.[src] Since the process of score calculation is repeated for every channel, Score-CAM is slow compared to gradient-based methods.[src] Moreover, it focuses on regions highlighted by individual feature maps, ignoring the context of the full image, reducing interpretability in complex scenes.[src] w_k^C(x,y) = ReLU(\frac{\partial y^C}{\partial A_k(i,j)}(x,y)) The activations are then weighted, and the final class activation map is retrieved by summing over the channels.[src] L_{Layer-CAM}^C(x,y) = ReLU(\sum_k w_k^C(x,y) A_k(x,y)) This technique offers high-resolution heatmaps, flexible localization, and per-location precision, employing positive gradients.[src]
39 sentences · 39 cited inline · 0 references stored
References
No reference rows published for this article.
Cite this article
MLA
"Class activation mapping." encyclopegia.org, 2026, https://encyclopegia.org/wiki/class-activation-mapping. Accessed 27 November 2026.
Chicago
"Class activation mapping." encyclopegia.org. Accessed November 27, 2026. https://encyclopegia.org/wiki/class-activation-mapping.
APA
encyclopegia.org. (2026). Class activation mapping. Retrieved November 27, 2026, from https://encyclopegia.org/wiki/class-activation-mapping
Accessed November 27, 2026 · CC BY-SA 4.0 · citation page · JSON