Conditional GAN Training Part (Curiosity)

Hello, I just wanted to ask a very simple thing in the training code of Conditional GAN. After training the Discriminator, when we train the Generator, in all the previous GANs, we have created new noise vectors, passed them through the generator to generate new fake images, and then used them further to update the generator’s weights. I have attached the SS of DCGAN as the reference below:

However, in the case of Conditional GAN, when training the generator, we have simply reused the fake images produced to update the discriminator’s weights, in order to update the generator’s weights as well, as can be seen in the below SS.

In other words, we haven’t produced new noise vectors, and hence, new fake images specifically for updating the generator’s weights. Is there some special reason for this as to why we do this in Conditional GAN, or can we do this in the training process of any GAN?

Thanks in advance!

Hey @mentor, can you please answer my query!

Hi @elemento,

Thanks for the reminder. Good question - very observant. Here are my thoughts:

Conceptually, conditional GANs use very much the same approach as “regular” GANs, and you theoretically could use the same approach with either, but you’d need to be careful about the detach(). When we pass the fake images to the discriminator, we detach() them. But, when we are training the generator, we don’t want to detach the fake images.

In the earlier assignments, creating a whole new set of images was an easy way to help make sure students didn’t accidentally use the same detached images when training the generator. But in the conditional GAN assignment, we can avoid this problem by just using combine_vectors() to create a new fake_image_and_labels. Since we never detached the original fake images, we can safely use those in combine_vectors().

Hey @Wendy, thanks a lot for this great explanation. Though, I have a small doubt. You mentioned that “Since we never detached the original fake images, we can safely use those in combine_vectors()” for conditional GAN, but when I look at the code of Conditional GAN, I can see that we are still calling detach on the fake images. I have attached the SS for your reference.

As can be seen in the first line of code, for updating the discriminator, we have called detach on the fake images. Please do correct me in case I am misunderstanding your answer.

Oh! Good point, @Elemento! I was not thinking straight. Since detach() returns a copy of the tensor, it would only be a problem if the generator reused the same copy as the discriminator used, which is not the case in the earlier assignments. So, my theory about why those assignments didn’t use the same fake images for the generator as it used for the discriminator is wrong. Maybe they just did it to help emphasize that the generator is being trained separately from the discriminator.

In any case, there is nothing special about conditional GANs as far as this approach is concerned. If you take the later courses in the GAN specialization, you’ll see other exercises where the generator uses the same fake images as the discriminator. (It is, of course, important to use a different set of fake images each time we loop through and call the generator again. The main thing is that the generator is trained against a range of images.).

If you’re curious, you could try an experiment and go back and try one of the old exercises using the fake_noise instead of fake_noise_2 for the generator and check that your results are similar quality to what you get using fake_noise_2.

Thanks a lot, @Wendy for your help and time. If possible, I have some other queries as well, which I have posted on the forum. Can you please take some time and resolve them as well, it would help me a lot!