# How does the generator in GAN's work?

After reading a lot of articles (for instance, this one - https://developers.google.com/machine-learning/gan/generator), I've been wondering: how does the generator in GAN's work?

What is the input to the generator? What is the meaning behind "input noise"?

As I've read, the only input that the generator receives is a random noise, which is weird.

If I would like to create a similar picture of $$x$$, and put as an input a matrix of random numbers (noise) - it would take A LOT of training until I would get some sort of picture $$x^*$$, that is similar to the source picture $$x$$.

The algorithm should receive some type of reference or a basic dataset (for instance, the set of $$x$$'s) in order to start the generation of the fake image $$x^*$$.

### What's the input to the Generator?

In the basic implementation of GANs, the Generator only takes in a vector of random variables. This might seem strange, but after training, the generator can transform this input noise into an image resembling those of the training set.

### How does it work?

It is trained along with its counterpart the Discriminator, whose goal is to distinguish real images (i.e. the dataset's images) from fake ones (i.e. images produced by the Generator). The Generator's goal in training is to fool the Discriminator into thinking that its images are real.

### Training process

In the beginning, where they are both untrained, they are both "terrible" at their respective tasks. The Generator can't produce anything resembling an image, but the Discriminator can't distinguish real from fake. As training progresses, the Discriminator starts identifying ways to distinguish the real images from the fake ones (i.e. patterns that appear in real images, but not in fake ones). The Generator, however, in its attempt to fool the Discriminator, starts producing those same patterns in its own images. After a while of both models becoming better at their respective tasks, we reach a point where the Generator can produce realistic images and the Discriminator is very good at distinguishing between real or fake.

Edit as suggested from comment:

A vector of random values is used as an input, so that the Generator can learn to generate unique outputs. In itself the Generator is deterministic, meaning that it has no internal sources of randomness. If we give it the same input vector twice, it will produce the same output both times. Thus, we feed the Generator with random values, so that it can learn to produce different outputs, depending on those values.

• But you haven't explained how the generator works, as in the question. I.e. what kind of algorithm does the generator use to create a convincing dataset, and how does the "learning" work for that algorithm? Jan 17 '20 at 18:05
• It's a neural network whose output has the same shape as the input. In a lot of cases it resembles an inverted discriminator (which is a typical binary classifier). Jan 18 '20 at 1:12
• @Djib2012 What do you mean by same shape? I will try to simplfy my question - if the fake image x* is this marix: [1,2,3], in the worse case it would take 10^3~ of iterations of generator-discriminator until I recieve the required x*. Since real images represented by larger matrix, it would be many many more than I described. Why wouldnt you insert as an input an example of real image x? Jan 18 '20 at 17:15
• If your dataset has let's say RGB images (i.e. $3$ channels) with a resolution of $256 \times 256$, the Generator should take a vector of random numbers as its input and output a tensor of $256 \times 256 \times 3$ (its output should have the same shape as the input images). Jan 18 '20 at 17:17
• You are thinking of it the wrong way. The generator doesn't search through all possible combinations of values so that it can produce an exact replica of the input images. It just tries to confuse the Discriminator. How does it do that? By mimicking the "patterns" that the Discriminator sees in real images when trying to distinguish them from fake ones. Jan 18 '20 at 17:19