deep-learning-with-python-notebooks
deep-learning-with-python-notebooks copied to clipboard
5.4.3 Visualizing heatmaps of class activation: Dimension Error?
This issue occurred when I tried to visualize heatmaps of class activation. First, I copied the sample code on the e-book and got this error:
IndexError Traceback (most recent call last)
<ipython-input-4-d07470776a6e> in <module>()
14 for i in range(512):
15
---> 16 conv_layer_output_value[:, :, i] *= pooled_grads_value[i]
17
18 heatmap = np.mean(conv_layer_output_value, axis=-1)
IndexError: index 14 is out of bounds for axis 2 with size 14
Then I tried to print the shape of conv_layer_output_value.shape
, and then I got this:
(1, 14, 14, 512)
Then I realized the 16th line should be
conv_layer_output_value[:, :, :, i] *= pooled_grads_value[i]
And this sentence should be added before visualizing the heatmap:
heatmap = np.squeeze(heatmap, axis=0)
I've compared other part of my code and sample code, yet found no difference. I think maybe there's a dimension error that should be corrected. If that's the case, should I pull a request?