In the simple GAN here, I noticed when we train the generator, we are not directly training it by mapping the noise input (length 100 vector) to an image (28*28 matrix).

Instead, the author is using the whole GAN and disable the discriminator to train the Generator (see below).

        # Train discriminator
        discriminator.trainable = True
        dloss = discriminator.train_on_batch(X, yDis)

        # Train generator
        noise = np.random.normal(0, 1, size=[batchSize, randomDim])
        yGen = np.ones(batchSize)
        discriminator.trainable = False
        gloss = gan.train_on_batch(noise, yGen)

Could anyone tell me why? Can we directly train generator by doing length 100 vector input and 28*28 output, like sequence to sequence model?


1 Answer 1


It's necessary to run both the generator and the discriminator to train the generator because the generator loss is dependent on the outputs of the discriminator.

The discriminator isn't disabled, it's just set so that the weights won't update when we do an update on the generator.

  • $\begingroup$ +1 and thanks for the answer. so, my question is why generator loss is dependent on the outputs of the discriminator? can we directly train the generator? that we define the generator loss that is not depending on the discriminator's loss $\endgroup$
    – Haitao Du
    Jul 16, 2018 at 9:53
  • $\begingroup$ The whole point of GAN is that you would like the generator to produce images indistinguishable with real images. The job of the discriminator is to judge do the distinguishing, and the generator tries to make it harder for the discriminator to judge. This requires the outputs of the discriminator to be known, so I very much doubt you can leave out discriminator when training. $\endgroup$
    – shimao
    Jul 16, 2018 at 16:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.