# Explainable Artificial Intelligence: Advancements and Limitations
## 4 Visual Explanations
### Pixel Attribution
#### 4.2.2 Class Activation Mapping (CAM)  
Another group of methods, CAM, leverage the final convolutional layer of DNNs, which is shown to capture the most meaningful and complete object signals [62]. Unlikebackpropagation-based approaches, CAM focuses on high-level features within these layers rather than tracing gradients or activations back to the input pixels. The first CAM method, introduced by [PERSON] et al., was designed for architectures incorporating a global average pooling (GAP) layer between the final convolutional and classification layers [76]. In this method, the GAP layer computes a scalar value \(F^{k}\) for each feature map \(\mathbf{f}^{k}\), which is then passed to the classification layer along with weights \(\mathbf{w}\) for \(k=1,\dots,K\). The class score for a particular class \(c\) is calculated as \(S_{c}=\sum w_{c}^{k}F^{k}\), where \(w_{c}^{k}\) denotes the contribution of \(F^{k}\)--and by extension, the feature map \(\mathbf{f}^{k}\)--to the score for class \(c\). Each feature map \(\mathbf{f}^{k}\) in the final convolutional layer, prior to the GAP operation, is expected to highlight the region that corresponds to the concept it represents when scaled by its calculated weight \(w_{c}^{k}\). For instance, in a face recognition task, a feature map activated by the nose might receive a high weight, while one responding to unrelated features, such as a car wheel, would be assigned a low or even negative weight. The weighted sum of these feature maps is then upsampled to the input image's resolution, producing a saliency map that highlights the most relevant regions for the examined class. A key limitation of the CAM approach is that it can only be applied to CNNs with a GAP layer between the last convolutional and classification layers, such as GoogleNet [47]. For architectures lacking this structure, CAM requires modifying the model by adding a GAP layer after the final convolutional layer. However, this alteration necessitates model retraining, which can lead to performance degradation compared to the original model. GradCAM [80] was introduced to overcome the limitations of CAM, particularly its dependency on GAP and successfully used in case studies such as in [92]. As a generalisation of CAM, GradCAM eliminates the need for specific model types or architectural modifications, making it more versatile and broadly applicable. This is achieved thanks to the way GradCAM weighs each feature map; differently from CAM, it takes the gradients of the output score \(S_{c}\) for a given class \(c\) with respect to each feature map \(\mathbf{f}^{k}\) at the last convolutional layer, i.e., \(\frac{\partial S_{c}}{\partial\mathbf{f}^{k}},k=1,\dots,K\). After this process, \(K\) different gradient maps are obtained. Finally, by applying GAP, a single weight  
\[w_{c}^{k}=\frac{1}{Z}\sum_{i}\frac{\partial S_{c}}{\partial f_{i}^{k}} \tag{1}\]  
for each feature map is obtained, where \(i\) indicates the location of each pixel and \(Z\) is the total number of pixels in the feature map \(\mathbf{f}^{k}\). Following that, similar to CAM, a weighted sum of the feature maps generates a heatmap with the same dimensions as \(\mathbf{f}^{k}\); also, see Figure 3 for an illustration. ReLU is also applied to keep features that positively affect a given class and ignore the negative signals that probably are for the other classes. Lastly, acquired heatmaps are upsampled to the size of the input image to highlight important parts of it. In addition, the authors showed how to obtain more class-discriminative and fine-grained results using simple element-wise multiplication between saliency maps generated with GradCAM and guided backpropagation [73]. More approaches were proposed to further refine the resulting activation maps of GradCAM. For instance, [PERSON] et al. proposed the GradCAM++ method to generate better localisation and handle multiple instances in a single image [93].