How to do it...

With this strategy in place, let's code up our solution as follows (Please refer to Transfer_learning.ipynb file in GitHub while implementing the code):

  1. Import the pre-trained model:
from keras.applications import vgg16from keras.utils.vis_utils import plot_modelfrom keras.applications.vgg16 import preprocess_inputvgg16_model = vgg16.VGG16(include_top=False, weights='imagenet',input_shape=(300,300,3))

Note that we are excluding the last layer in the VGG16 model. This is to ensure that we fine-tune the VGG16 model for the problem that we are trying solve. Additionally, given that our input image shape is 300 X 300 X 3, we are specifying the same while downloading the VGG16 model.

  1. Preprocess the set of images. This preprocessing ...

Get Neural Networks with Keras Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.