Now that you've built your own CNN and seen how to visualize feature maps, its time to practice loading a pretrained model from file and visualize the learned features systematically. In this lab, you'll expand upon the code from the previous lesson in order to succinctly visualize all the channels from each layer in a CNN.
In this lab you will:
- Load a saved Keras model
- Use Keras methods to visualize the activation functions in CNNs
For this lab, load the saved model 'cats_dogs_downsampled_with_augmentation_data.h5'
. This saved file includes both the model architecture and the trained weights. See the model.save()
method for further details. The model was built in order to help identify cat and dog pictures. Start simply by loading the model and pulling up a summary of the layers. (To load the model use the keras.models.load_model()
function.)
# Some code to stop comments from tf
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
# Your code here
Before you plot the learned representations of the convolutional base, let's import an image and display it prior to processing. This will provide a comparison to the transformations formed by the model's feature maps.
Load and display the image 'dog.1100.jpg'
.
# Your code here
Recall that you should always preprocess images into tensors when using deep learning. As such, preprocess this image and then redisplay the tensor.
# Your code here
Now that you've loaded a model, practice visualizing each of the channels for each of feature maps of the convolutional layers. Recall that this process will take a few steps. First, extract the feature maps, or layer outputs from each of the activation functions in the model. From there, generate models that transform the image from its raw state to these feature maps. You can then take these transformations and visualize each channel for each feature map.
You may want to take a look at the solution branch to help you with this. Note you'll likely get a warning here for runtime, but it does not effect the output.
# Your code here
Nice work! In this lab, you practiced loading a model and then visualizing the activation feature maps learned by that model on your data! In the upcoming labs and sections you will build upon the first part of this and see how you can adapt the representations learned by more experienced models to your own applications which may have limited training data.