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


#creating a VGG16 model using fully connected layers also because then we can 
#visualize the patterns for individual category
from keras.applications import VGG16
model = VGG16(weights='imagenet'include_top=True)

#finding out the layer index using layer name
#the find_layer_idx function accepts the model and name of layer as parameters and return the index of respective layer
layer_idx = utils.find_layer_idx(model'predictions')
#changing the activation of the layer to linear
model.layers[layer_idx
.activation = activations.linear
#applying modifications to the model
model = utils.apply_modifications(model)
#Indian elephant
img3 = visualize_activation(modellayer_idxfilter_indices=385max_iter=5000verbose=True)
plt.imshow(img3)

我们的模型使用随机输入对印度象进行分类 , 生成了以下输出:

从上面的图像中 , 我们可以观察到该模型需要像牙齿 , 大眼睛和象牙这样的结构 。 现在 , 这些信息对于我们检查数据集的完整性非常重要 。 因为印度象通常存在于长满树木或长草的栖息地中 , 所以模型可能会侧重于背景中的栖息地特征 , 而这是不对的 。

推荐阅读