Member-only story
Transfer Learning for Image Classification — (4) Visualize VGG-16 Layer-by-Layer

VGG-16 and ResNet made their names in the ImageNet Challenge in 2014 and 2015. Both continue to be used by many practitioners now. In the previous chapter we learned a general Convolutional Neural Network framework, now we want to understand the specifics of VGG-16. In this chapter, we will load the VGG-16 model and the ResNet model. I will visualize the inputs and outputs layer-by-layer to show you what VGG-16 “sees” an image. You will witness how VGG-16 creates features and what they look like. We will use VGG-16 as the primary case. After reading this chapter, you can apply the same approach to understand other pre-trained models.
Here are some basics of the two models. “VGG-16” is named after the Visual Geometry Group from Oxford. The “16” in VGG-16 refers to the 16 weighting layers. They are the 13 convolutional layers and the 3 fully connected layers. The pooling layers do not have parameters to train so are not counted in the 16. How about ResNet? It stands for Residual Network. We have learned the ResNet model in “Chapter 2: The stories of pre-trained models”. Interested readers are recommended to review Chapter 2.
(A) We Will Use Tensorflow & Keras
When people talk about the top modules for deep learning, Tensorflow is one of them. TensorFlow is an open-source platform for machine learning. It has many libraries and community resources. It enables ML developers to build and deploy ML applications easily. Keras is an open-source deep-learning API written in Python. It supports Tensorflow or Theano. Big companies such as Microsoft, NVIDIA, Google, and Amazon have contributed actively to Keras’ growth. My Python notebook is available via this link.
(B) Load the Pre-trained Models: VGG-16 and ResNet
We can use Keras to load a pre-trained model. Let’s load VGG-16 first.
A pre-trained model saves all its secret ingredients in its parameters. The code weights='imagenet'
loads the parameters of the…