3
$\begingroup$

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?

$\endgroup$
  • 2
    $\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$ – John Doucette May 18 at 22:55
2
$\begingroup$

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".

$\endgroup$
  • $\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 May 19 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 May 19 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$ – John Doucette May 19 at 18:48
0
$\begingroup$

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.

$\endgroup$
  • $\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 Oct 2 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 Oct 2 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 Oct 2 at 8:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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