Grad-CAM class activation visualization
Author: fchollet
Date created: 2020/04/26
Last modified: 2021/03/07
Description: How to obtain a class activation heatmap for an image classification model.
Adapted from Deep Learning with Python (2017).
Setup
Configurable parameters
You can change these to another model.
To get the values for last_conv_layer_name
use model.summary()
to see the names of all layers in the model.
The Grad-CAM algorithm
Let's test-drive it
```
1/1 ━━━━━━━━━━━━━━━━━━━━ 3s 3s/step
Predicted: [('n02504458', 'African_elephant', 9.860664)]
Let's try another image
We will see how the grad cam explains the model's outputs for a multi-label image. Let's try an image with a cat and a dog together, and see how the grad cam behaves.
```
1/1 ━━━━━━━━━━━━━━━━━━━━ 0s 11ms/step
Predicted: [('n02112137', 'chow', 4.610808), ('n02124075', 'Egyptian_cat', 4.3835773)]
We generate class activation heatmap for "egyptian cat," the class index is 285