concept Grad - CAM in category AI

appears as: Grad-CAM
Interpretable AI MEAP V03

This is an excerpt from Manning's book Interpretable AI MEAP V03.

In Chapter 5, we will focus on convolutional neural networks which is a more advanced form of architecture used mainly for visual tasks such as image classification and object detection. We will learn how to visualize what the model is focusing on using saliency maps. We will learn techniques such as Gradients, Guided Backpropagation (Backprop for short), Gradient-weighted Class Activation Mapping (Grad-CAM), guided Grad-CAM and Smooth Gradients (SmoothGrad).

In the previous chapter, we looked at deep neural networks and learned how to interpret them using model agnostic methods that are local in scope. We specifically learned three techniques – LIME, SHAP and Anchors. In this chapter, we will focus on Convolutional Neural Networks (CNNs), a more complex neural network architecture used mostly for visual tasks such as image classification, image segmentation, object detection and facial recognition. The techniques learned in the previous chapter can be applied to CNNs and we will learn how to do that. In addition, we will also focus on saliency mapping, which is a local, model dependent and post-hoc interpretability technique. Saliency mapping is a great tool to interpret CNNs as it helps us visualize the salient or important features for the model. We will specifically be covering techniques such as vanilla backpropagation, guided backpropagation, integrated gradients, SmoothGrad, Grad-CAM and guided Grad-CAM.

Figure 5.21: Activation Map using Grad-CAM

In order to get a more fine-grained activation map, we can use the guided Grad-CAM technique. The guided Grad-CAM technique was proposed in 2017 by the same authors as Grad-Cam and it essentially combines the Grad-CAM and guided backpropagation techniques. The final activation map produced by guided Grad-CAM is an element-wise dot product of the activation map produced by Grad-CAM and the saliency map produced by guided backpropagation. This is implemented in the function below.

# Code below from: https://github.com/utkuozbulak/pytorch-cnn-visualizations
def guided_grad_cam(grad_cam_mask, guided_backprop_mask):
    """
        Guided grad cam is just pointwise multiplication of cam mask and
        guided backprop mask
    Args:
        grad_cam_mask (np_arr): Class activation map mask
        guided_backprop_mask (np_arr):Guided backprop mask
    """
    cam_gb = np.multiply(grad_cam_mask, guided_backprop_mask)
    return cam_gb

The function above takes the mask in grayscale obtained from Grad-CAM and guided back propagation and returns an element-wise product of them. Figure 5.22 shows the activation maps produced by guided Grad-CAM for the two examples of interest. We can see that visualization is a lot cleaner than guided backpropagation and highlights areas that are consistent with IDC negative and positive patches.

sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest