How to do it...

We proceed with the recipe as follows:

  1. Import matplotlib and the modules used by keras-vis. In addition, also import the pre-built VGG16 module. Keras makes it easy to deal with this pre-built network:
from matplotlib import pyplot as pltfrom vis.utils import utilsfrom vis.utils.vggnet import VGG16from vis.visualization import visualize_class_activation
  1. Access the VGG16 network by using the pre-built layers included in Keras and trained with ImageNet weights:
# Build the VGG16 network with ImageNet weightsmodel = VGG16(weights='imagenet', include_top=True)model.summary()print('Model loaded.')
  1. This is how the VGG16 network looks internally. We have many ConvNets, alternated with maxpool2D. Then, we have a Flatten layer ...

Get TensorFlow 1.x Deep Learning 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.