We proceed with the recipe as follows:
- 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
- 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.')
- This is how the VGG16 network looks internally. We have many ConvNets, alternated with maxpool2D. Then, we have a Flatten layer ...