VGG19 network

We will use the pre-trained VGG19 network. The purpose of the VGG19 network is to extract feature maps of the generated and the real images. In this section, we will build and compile the VGG19 network with pre-trained weights in Keras:

  1. Start by specifying the input shape:
input_shape = (256, 256, 3)
  1. Next, load a pre-trained VGG19 and specify the outputs for the model:
vgg = VGG19(weights="imagenet")
vgg.outputs = [vgg.layers[9].output]
  1. Next, create a symbolic input_tensor, which will be our symbolic input to the VGG19 network, as follows:
input_layer = Input(shape=input_shape)
  1. Next, use the VGG19 network to extract the features:
features = vgg(input_layer)
  1. Finally, create a Keras model and specify the inputs and outputs for the network:
model = Model(inputs=[input_layer], outputs=[features])

Finally, wrap the entire code for the VGG19 model inside a function, as follows:

def build_vgg():
"""
Build the VGG network to extract image features
"""
input_shape = (256, 256, 3)

# Load a pre-trained VGG19 model trained on 'Imagenet' dataset
vgg = VGG19(weights="imagenet")
vgg.outputs = [vgg.layers[9].output]

input_layer = Input(shape=input_shape)

# Extract features
features = vgg(input_layer)

# Create a Keras model
model = Model(inputs=[input_layer], outputs=[features])
return model
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.14.144.229