concept combine model in category deep learning

appears as: combined model, The combined model
Deep Learning for Vision Systems

This is an excerpt from Manning's book Deep Learning for Vision Systems.

As you can see in Figure 8.11, when training the combined model, we freeze the weights of the discriminator because this model focuses only on training the generator. We will discuss the intuition of this idea when we explain the generator training process in the next section. For now, just know that we need to build and train two models, one for the discriminator alone and the other one is for both G and D models.

Both processes follow the traditional neural network training process that was explained in chapter 2. It starts with the feedforward process, then make predictions, calculate the error and backpropagate the error. When training the discriminator, the error is backpropagated back to the discriminator model to update its weights whereas in the combined model, the error is backpropagated back to the generator to update its weights.

Here is the one tricky part in training GANs, training the generator. While the discriminator can be trained in isolation from the generator model, the generator needs the discriminator to be trained. For this, we build a combined model that contains both the generator and the discriminator as you can see in Figure 8.12.

Figure 8.12: illustration of the combined model that contains both the generator and discriminator models.
  • the second time when we build the combined model. In which, we freeze the weights of the discriminator model and the error is backpropagated to the generator model to update its weights.
  • Now let’s build the combined model:

    # Build the generator
           generator = generator_model()
     
           # The generator takes noise as input and generates image
           z = Input(shape=(100,))
           image = generator(z)
     
           # freeze the weights of the discriminator model
           discriminator.trainable = False
     
           # The discriminator takes generated images as input and determines validity
           valid = discriminator(img)
     
           # The combined model  (stacked generator and discriminator)
           # Trains the generator to fool the discriminator
           combined = Model(z, valid)

    Now that we have built the combined model, we can proceed with the training process as our normal process. We compile the combined model with a binary_crossentropy loss function and an optimizer Adam.