1
votes

My question is simple. I want to visualize what filters are used in ConvNet in deep layers to extract the features predicting the final model. By visualize I mean to save it in .png format like filters shown in final layer of https://s3-ap-south-1.amazonaws.com/av-blog-media/wp-content/uploads/2018/03/cnn_filters.png , we can actually see a car in final layer filters

I can visualise the filters of first convolutional layer by help provided from my own question Visualising Keras CNN final trained filters at each layer but that shows only to visualise for first layer. First layer filters look like some random coloured 3x3 pixel images. But I want to see the final layer filters like the car filter in the first link.

First layer filters look like some random coloured 3x3 pixel images. But I want to see the final layer filters like the car filter in the first link. Even the article of car filter https://www.analyticsvidhya.com/blog/2018/03/essentials-of-deep-learning-visualizing-convolutional-neural-networks/ has code for only first layer

2

2 Answers

1
votes

You can adress the weights of the different layers by:

w = model.layers[i].get_weights()[0][:,:,:,:]

where i is the number of your layer.

In case of the picture in the link I am not sure if it is actually the weights or maybe the activation map which is shown. You could get that one by:

from keras import backend as K

get_output = K.function([model.layers[0].input],[cnn.layers[i].output])
output_normal = get_output([X])[0][m]

where m is the number of a certain image in X as input.

1
votes

The Python library keras-vis is a great tool for visualizing CNNs. It can generate conv filter visualizations, dense layer visualizations, and attention maps. The latest release is quite old (and a little bit buggy), so I recommend installing from master:

pip install git+https://github.com/raghakot/keras-vis.git