Visualizing the Convolutions and Pooling

Hey there,

I have couple of questions regarding the topic title.

  1. Why does activation_model.predict takes in array index of x outside the predict function?
  f1 = activation_model.predict(test_images[FIRST_IMAGE].reshape(1, 28, 28, 1))[x]
  f2 = activation_model.predict(test_images[SECOND_IMAGE].reshape(1, 28, 28, 1))[x]
  f3 = activation_model.predict(test_images[THIRD_IMAGE].reshape(1, 28, 28, 1))[x]


2.What does the each value mean in f1,f2,f3 array ?

f3[0, : , :, CONVOLUTION_NUMBER]
f1[0, : , :, CONVOLUTION_NUMBER]
f2[0, : , :, CONVOLUTION_NUMBER]

Please help me out in this regard!.

Thank you!

Part 1
Please look at the model definition.
activation_model outputs predictions for all layers of the trained model.
For each image, the model outputs an array of predictions, one for each layer.
The code snippet aims to plot the output of the first 4 layers.

Part 2
Consider the first conv layer. It has has 64 filters. Author is picking the output of the 2nd filter as an example for generating the plot.
You can pick any output by adjusting the CONVOLUTION_NUMBER between 0 and 63.

1 Like

Thanks for the quick and elaborate response, that cleared the most part of my query.

But in Part-2, What’s the first value(0) in the f1 array signify ?.

Moreover, I assume 2nd and 3rd value [:,:] signify the shape of the image [here 28,28], please correct me if I am wrong.

Thanks in advance.

For each input batch, activation_model generates a list of outputs.
The length of the list corresponds to the number of outputs produced. Since the model generates 7 outputs, the length of the list is 7.
Each entry within the output is of the form [batch, layer specific output dimensions].
We use only 1 input. So, we can select the layer specific output by looking into the 0th index.
To itereate, f1 corresponds to the xth layer output.
f1[0] corresponds to the layer output for the 1st input.
f1[0, :, :, CONVOLUTION_NUMBER] extracts all rows and columns for a specific filter.

1 Like