I've been doing some reading about GANs, and although I've seen several excellent examples of implementations, the descriptions of why those patterns were chosen isn't clear to me in many cases.

At a very high level, the purpose of the discriminator in a GAN is establish a loss function that can be used to train the generator.

ie. Given the random input to the generator, the discriminator should be able to return a probability of the result being a 'real' image.

If the discriminator is perfect the probability will always be zero, and the loss function will have no gradient.

Therefore you iterate:

  • generate random samples
  • generate output from the generator
  • evaluate the output using the discriminator
  • train the generator
  • update the discriminator to be more accurate by training it on samples from the real distribution and output from the generator.

The problem, and what I don't understand, is point 5 in the above.

Why do you use the output of the generator?

I absolutely understand that you need to iterate on the accuracy of the discriminator.

To start with it needs to respond with a non-zero value for the effectively random output from the generator, and slowly it needs to converge towards correctly classifying images at 'real' or 'fake'.

In order to achieve this we iterate, training the generator with images from the real distribution, pushing it towards accepting 'real' images.

...and with the images from the generator; but I don't understand why.

Effectively, you have a set of real images (eg. 5000 pictures of faces), that represent a sample from the latent space you want the GAN to converge on (eg. all pictures of faces).

So the argument goes:

As the generator is trained iteratively closer and closer to generating images from the latent space, the discriminator is iteratively trained to recognise from the latent space, as though it had a much larger sample size than the 5000 (or whatever) sample images you started with.

...ok, but that's daft.

The whole point of DNN's is that given a sample you can train it to recognise images from the latent space the samples represent.

I've never seen a DNN where the first step was 'augment your samples with extra procedurally generated fake samples'; the only reason to do this would be if you can only recognise samples in the input set, ie. your network is over-fitted.

So, as a specific example, why can't you incrementally train the discriminator on samples of ('real' * epoch/iterations + 'noise' * 1 - epoch/iterations), where 'noise' is just a random input vector.

Your discriminator will then necessarily converge towards recognising real images, as well as offering a meaningful gradient to the generator.

What benefit does feeding the output of the generator in offer over this?

  • 3
    $\begingroup$ In your title, you ask about using the output of the discriminator to train the generator, but in your question body, you ask about using the output of the generator to train the discriminator. I'm going to assume you mean what it says in the body, but you should edit the question to be self-consistent. $\endgroup$ Commented May 18, 2019 at 22:55

3 Answers 3


The main reason that the discriminator is trained concurrently with the generator is to provide (at least in theory) a smooth and gradual learning signal for the generator.

If we trained the discriminator on only the input data, then, assuming our training algorithm converges well, it should quickly converge to a fixed model. The generator can then learn to fool this fixed model, but it will likely still be easy to spot the generator's fakes for a human. For example, the discriminator may have learned that, coincidentally, in the sample you provided, all images of trucks have a fully white pixel in the top left corner. If it learns that pattern, the generator can fool it by generating noise with a white pixel. Once the generator has learned this pattern, all learning stops.

In contrast, suppose that the discriminator is repeatedly re-trained on a mixture of real and generated examples. The discriminator will be forced to learn more complex patterns than "white pixel in upper left", which improves its quality beyond the raw patterns in the sample data.

The converse relationship is also true. If the generator is trained only on the training data, it will also likely pick out only the most obvious patterns. These patterns are likely to create many local minima in the weight space for the network. However, if the error signal from the discriminator is fed to the generator, then the generator must adapt: in effect, we are telling it "making the top left pixel white is not good enough to fool observers. Find more complex patterns".

  • $\begingroup$ The discriminator is not going to be fooled by noise with a white pixel; it's been trained on pictures of trucks, it will recognise pictures of trucks. That's what NN's do. You're describing once again, augmenting your sample with additional fake samples, but all that proves if either a) your discriminator architecture is bad, or b) your sample is poor, surely? $\endgroup$
    – Doug
    Commented May 19, 2019 at 4:17
  • $\begingroup$ I believe the use of the generator output is to do with removing artifacting in the output, where say, 'truck like' images are recognized by the discriminator, but you want the discriminator to reject images which are 'truck like but have visual artifacts'. What I don't understand is how/why feeding the generator output in achieves this, other than, 'well, it seems to work pretty well in practice'. $\endgroup$
    – Doug
    Commented May 19, 2019 at 4:23
  • $\begingroup$ @Doug The white pixel example is an example of artifacting. I picked a deliberatively extreme example to illustrate it. From the discriminative NN's perspective, if all pictures of trucks in the sample have a while pixel, that's a strong signal for being a truck. However, since it is easy for the generator to mimic, the discriminator is forced to learn more complex signals from the dataset. This iterative process repeats until (hopefully), the generator outputs things that look like the trucks in the input data, and the discriminator can't tell them apart anymore. $\endgroup$ Commented May 19, 2019 at 18:48

The discriminator's job is to tell between real images and generated images. It would be impossible to do that if it never actually sees generated images, just as if you wanted a network to differentiate between cats and dogs it wouldn't work if you only showed it pictures of dogs.
If you were to train a generator on only real images, all labels it would see would be a 1. What you end up with is a network that learns how to produce 1 regardless of its inputs, which is very easy to learn without finding any underlying patterns in the data. Once you add in the generated images and 0 labels it is forced to learn something interesting.

  • $\begingroup$ This may superficially appear to be correct according to "common sense", but that's not the question I was asking. You don't need a discriminator to be trained on generated images; you just need a discriminator to be able to be 'fuzzy' in it's matching. Early on, it should be fooled by random noise, later on it should be fooled only be high quality real images, so it provides a gradient to the generator. However, as far as I can tell there's actually no specific need to feed it the output of the generator. $\endgroup$
    – Doug
    Commented Oct 2, 2019 at 8:07
  • $\begingroup$ That's simply a convenient way to generate the right 'sort' of characteristics from a discriminator. Indeed, as you note, a pre-trained 'perfect discriminator' would make learning impossible (no gradient)... but for example, you could mix in random noise samples into the discriminator training set, and incrementally remove the noise sample to reduce the 'fuzziness' as you progress with training. $\endgroup$
    – Doug
    Commented Oct 2, 2019 at 8:09
  • $\begingroup$ There's a lot of hand waving and 'common sense' about building GANs, but I contend it's a lot more 'this example works in practice and we're just tweaking it' than 'we actually understand why the dynamic equilibrium produces the right sort of discriminator network'. $\endgroup$
    – Doug
    Commented Oct 2, 2019 at 8:14

It turns out there is actually a practical reason for this.

Practically speaking, in GANs the generator tends to converge on few 'good' outputs that fool the discriminator if you don't do it. In the optimal case, the generator will actually emit a single fixed output regardless of the input vector that fools the discriminator.

Which is to say, the generators loss function is intended not simply as "fool the discriminator", it is actually:

  • Fool the discriminator.
  • Generate novel output.

You can write your generator's loss function to explicitly attempt to say the output in any training batch should be distinct, but by passing the outputs to the discriminator you create a history of previous predictions from the generator, effectively applying a loss metric for when the generator tends to produce the same outputs over and over again.

...but it is not magic, and is not about the discriminator learning "good features" features; it is about the loss applied to the generator.

This is referred to as "Mode Collapse", to quote the Google ML guide on GAN troubleshooting:

If the generator starts producing the same output (or a small set of outputs) over and over again, the discriminator's best strategy is to learn to always reject that output. But if the next generation of discriminator gets stuck in a local minimum and doesn't find the best strategy, then it's too easy for the next generator iteration to find the most plausible output for the current discriminator.

Each iteration of generator over-optimizes for a particular discriminator, and the discriminator never manages to learn its way out of the trap. As a result the generators rotate through a small set of output types. This form of GAN failure is called mode collapse.

See also, for additional reading "Unrolled GANs" and "Wasserstein loss".

see: https://developers.google.com/machine-learning/gan/problems


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .