Ungraded lab: C1 W3

f1 = activation_model.predict(test_images[FIRST_IMAGE].reshape(1, 28, 28, 1))[x]

what is x here?
Why is it giving error when I used x=7?

  1. x = loop counter. (see range construct in the same cell). x is used to refer the outputs of layers 0-3 i.e. Conv2D and MaxPooling2D layers (see original model)
  2. Since there are only 7 outputs generated by activation_model, index 7 is out of bounds.

Thanks @balaji.ambresh . Clear on the activation_model part. I think the error was also because of this line:
axarr[0,x].imshow(f1[0, : , :, CONVOLUTION_NUMBER], cmap='inferno')

Since 5th,6th and 7th output are 2-D tensors.

I have one more related question,
Why not directly use the model which was trained.?Why there is a need to create a new model activation_model for visualization?

Is it because the model can only return last layer. While in the activation_model all the intermediate layer is the output layer which can be returned and sliced/indexed…

Check the trace.

You are correct.