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 practice visualizing 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.
You will be able to:
- Load a saved model
- Visualize the filters produced by hidden layers in a CNN
For this lab, we have saved a model chest_xray_all_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 patients with pneumonia. Start simply by loading the model and pulling up a summary of the layers. (To load the model use the keras.models.load_model
method.)
#Your code here
Before we plot the learned representations of the convolutional base, let's import an image and display it prior to processing. This will provide us a comparison to the transformations formed by the model's feature maps.
Load and display the image person3_virus_16.jpeg.
#Your code here
Recall that we will always preprocess our images into tensors when using deep learning. As such, preprocess this image and then redisplay the tensor.
#Your code here
Now that we'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. From there, you can then take these transformations and visualize each channel for each feature map.
To preview the results of our solution code, take a sneek peak at the Intermediate_Activations_Visualized.pdf file.
#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.