1

anyone please tell me how to visualize the learned filter of each CNN layer? The following answers tell me how to only visualize the learned filters of the first CNN layer, but could not visulize the other CNN layers.

1) You can just recover the filters and use Matlab's functions to display them as images. For example after loading a pretrained net from http://www.vlfeat.org/matconvnet/pretrained/ :

imshow( net.layers{1}.filters(:, :, 3, 1), [] ) ;

2) You may find the VLFeat function vl_imarraysc useful to display several filters. http://www.vlfeat.org/matlab/vl_imarraysc.html

Addee
  • 663
  • 10
  • 21
  • 2
    The first layer has 1 (grayscale) or 3 (color) channels. The other layers has a lot more channels (e.g, 64, 128, 512). If you have more than 3 channels, it's not clear how to visualize channels at the same time. You can look at one channel at a time e.g.,: net.layers{2}.filters(:, :, 21, 1), the same way as you visualize the first layer filters. Let me know – DataHungry Jun 07 '17 at 07:08
  • @DataHungry I have seen many papers in which they shown the features are different layers. Are they showing one channel? – Addee Jun 08 '17 at 05:34

1 Answers1

4

For visualizing filters in intermediate layers. There are several techniques:

(1) show one or three channels as grayscale or RGB at a time. It's not very informative since they filters of ResNet and VGG are small 3x3.

(2) Turn off other units. Backpropgate only this unit to the input space. You can see a pattern that reflects what this unit cares about. There are many papers that use similar techniques. e.g., Zeiler, Matthew D., and Rob Fergus. "Visualizing and understanding convolutional networks." European conference on computer vision. 2014.

(3) Find input patches that maximally activate this unit and see what they are.

DataHungry
  • 351
  • 2
  • 9
  • Thanks for mentioning the techniques. Is there are implemented code for these techniques? – Addee Jun 12 '17 at 01:43
  • @Addee I don't immediately know there are implementations. They are not difficult to implement. Take (2) for example, you can simply do what I described: Turn off other units. Backpropgate only one unit of interest to the input space (i.e., input image). You will see some patterns. BTW, it be interested to see some of such visualizations if you can post them somewhere. – DataHungry Jun 12 '17 at 03:16
  • @Addee. Method #3 is implemented for TF in github.com/kukuruza/TF-Visualize-CNN – etoropov May 25 '18 at 15:22