The adversarial network is a combined network that uses the generator, the discriminator, and VGG19. In this section, we will create an adversarial network.
Perform the following steps to create an adversarial network:
- Start by creating an input layer for the network:
input_low_resolution = Input(shape=(64, 64, 3))
The adversarial network will receive an image of a shape of (64, 64, 3), which is why we have created an input layer.
- Next, generate fake high-resolution images using the generator network, as follows:
fake_hr_images = generator(input_low_resolution)
- Next, extract the features of the fake images using the VGG19 network, as follows:
fake_features = vgg(fake_hr_images)
- Next, make the discriminator network non-trainable in the adversarial network:
discriminator.trainable = False
We are making the discriminator network non-trainable because we don't want to train the discriminator network while we train the generator network.
- Next, pass the fake images to the discriminator network:
output = discriminator(fake_hr_images)
- Finally, create a Keras model, which will be our adversarial model:
model = Model(inputs=[input_low_resolution], outputs=[output,
fake_features])
- Wrap the entire code for the adversarial model inside a Python function:
def build_adversarial_model(generator, discriminator, vgg):
input_low_resolution = Input(shape=(64, 64, 3))
fake_hr_images = generator(input_low_resolution)
fake_features = vgg(fake_hr_images)
discriminator.trainable = False
output = discriminator(fake_hr_images)
model = Model(inputs=[input_low_resolution],
outputs=[output, fake_features])
for layer in model.layers:
print(layer.name, layer.trainable)
print(model.summary())
return model
We have now successfully implemented the networks in Keras. Next, we will train the network on the dataset that we downloaded in the Data preparation section.