Chapter 8: Transfer Learning and Pre-trained Models
Activity 15: Use the VGG16 Network to Train a Deep Learning Network to Identify Images
Solution:
- Import the libraries:
import numpy as np
from keras.applications.vgg16 import VGG16
from keras.preprocessing import image
from keras.applications.vgg16 import preprocess_input
- Initiate the model. (Note that at this point, you can also view the architecture of the network, as follows.):
classifier = VGG16()
print(classifier.summary())
classifier.summary () shows us the architecture of the network. The following points should be noted: It has a four-dimensional input shape (None, 224,224,3) and it has three convolutional layers.
The last four layers of the output are:
Figure 8.29: The architecture of the network
- Load the image. ‘../Data/Prediction/test_image_1.jpg’ is the path of the image on our system. It will be different on your system:
new_image= image.load_img(‘../Data/Prediction/test_image_1.jpg’, target_size...