Path: blob/master/examples/vision/ipynb/grad_cam.ipynb
3236 views
Kernel: Python 3
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
In [0]:
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.
In [0]:
The Grad-CAM algorithm
In [0]:
Let's test-drive it
In [0]:
Create a superimposed visualization
In [0]:
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.
In [0]:
We generate class activation heatmap for "chow," the class index is 260
In [0]:
We generate class activation heatmap for "egyptian cat," the class index is 285
In [0]: