fchollet / deep-learning-with-python-notebooks

Jupyter notebooks for the code samples of the book "Deep Learning with Python"
MIT License
18.17k stars 8.53k forks source link

the Grad-CAM code should compute the gradient of the score for class c , yc before the softmax #107

Open ruoyu0088 opened 5 years ago

ruoyu0088 commented 5 years ago

here is the code that calculate the gradient in the book:

african_e66lephant_output = model.output[:, 386]
grads = K.gradients(african_elephant_output, last_conv_layer.output)[0]

But in the reference article https://arxiv.org/abs/1610.02391

we first compute the gradient of the score for class c , y c (before the softmax), with respect to feature maps A k of a convolutional layer

It's said that we need the value before softmax, so I think maybe the following code is correct:

african_e66lephant_output = model.output.op.inputs[0][0, 386]