一文带你用可视化理解卷积神经网络(20)

现在 , 我们将使用VGG16模型为图像生成显著性图:

# Utility to search for layer index by name. 
# Alternatively we can specify this as -1 since it corresponds to the last layer.
layer_idx = utils.find_layer_idx(model 'predictions')

# Swap softmax with linear
model.layers[layer_idx
.activation = activations.linear
model = utils.apply_modifications(model)

#generating saliency map with unguided backprop
grads1 = visualize_saliency(model layer_idxfilter_indices=Noneseed_input=image)
#plotting the unguided saliency map
plt.imshow(grads1cmap='jet')

我们看到该模型更侧重于狗的面部部分 。 现在 , 让我们看看反向传播的结果:

推荐阅读