How to do it...

In this section, we will code up the process of visualizing what the filters are learning across the convolution filters of the initial layers as well as the final layers.

We'll reuse the data that we prepared in the Gender classification using CNN recipe's Scenario 1 from step 1 to step 4 (please refer to Transfer_learning.ipynb file in GitHub while implementing the code):

  1. Identify an image for which you want to visualize the intermediate output:
plt.imshow(x[3])plt.grid('off')

  1. Define the functional API that takes the image as an input, and the first convolution layer's output as output:
from keras.applications.vgg16 import ...

Get Neural Networks with Keras Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.