Reputation: 439
I am new to GAN. I am learning to model GAN to generate images,however I don't really understand what exactly is the random noise given to the generator. Is it random numbers from 0 to 1 and what should be its size. Also should the random noise be constant every time the generator run?
Any help would be appreciated.
Upvotes: 7
Views: 11087
Reputation: 1
The Random vector is not actually random, typically we sample the vector from some specific distribution (Gaussian , Uniform etc). The generator takes the sampled vector and then it tries to map it to the distribution of the training data by minimising the Jensen-Shannon Divergence of the probability distribution of the sampled vector and the distribution of the all the training data. The size of the sampled vector which we feed to the generator is a Hyperparameter.
Upvotes: 0
Reputation: 10396
There is a jupyter notebook driven tutorial on github (full disclosure, it is my github). (Solutions available here)
The noise or rather latent random variable can be generated pretty much however you like for example such as follows:
# Generate latent random variable to feed to the generator, by drawing from a uniform distribution
z = np.random.uniform(-1., 1., size=[batch_size, noise_dim])
Yet it makes sense to think about the activation function within the input layer of your generator, and pay attention to its sensitive range.
The generator takes this input as a seed to decode from that latent variable into the source datasets domain. So obviously the same random variable will lead to the exact same generated sample.
So you should constantly be drawing new samples while training, and do not keep the noise constant.
Upvotes: 2
Reputation: 75
I'm also new to GAN but working recently on GAN for signal generation.
Random noise is the input to the generator. At the beginning it has no meaning and with training you try to find meaning to them. Regarding the size i'm still not sure if my conclusion is correct so I hope the others correct my if I'm wrong. We should search for the suitable size for our Problems. If latent space is very small, the model will reach a point which it can't produce better quality anymore (bottleneck) and if it's too big, the model will take very Long time to produce good results and it may even fail to converge. Usually one starts with latent space size used by others for same Problem.
Upvotes: 0
Reputation: 468
The random noise vector distribution represents the latent space. It is not that important for GANs but more so for Autoencoders. Typically, the noise is generated from the normal distribution but some researchers have reported improved training results using a spherical distribution (sorry, I don't have the references handy). The range of the noise depend on your input layer. If you are using images, you probably normalized the inputs between 0 and 1 or -1 and 1, so you would use a corresponding distribution range for your noise vector. A typical noise vector might be generated like so:
noise = tf.random.normal([BATCH_SIZE, noise_dim])
where BATCH_SIZE is the size of the training batch (16, 32, 64, 128...) and noise_dim is the size of the noise vector, which depends on your feature space (I use 1024 often for medium resolution images).
Upvotes: 2
Reputation: 378
Random noise is a feature vector, unique for every image
Let's consider noise vector of 128
For now just focus on 1st entry from vector let's consider it is for length of hairs on head
From training images model has learnt that for bald the value is=0 and for long hair value=1, by selecting random number from 0 to 1 decides amount of hairs. so model can generate persons of different hair length
In this way all 128 entries in random noise will decide one factor of human face
That's why every time choosing random noise will generate new person image
If you use random noise same every then model will generate same image
I hope you understood how GAN works.
Upvotes: 8