# Why we train the generative model “indirectly” in GAN(generative adversarial networks)?

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

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.

• +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 – Haitao Du Jul 16 '18 at 9:53
• 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. – shimao Jul 16 '18 at 16:27