Conditional GANs

We know that the generator generates new images by learning the real data distribution, while the discriminator examines whether the image generated by the generator is from the real data distribution or fake data distribution.

However, the generator has the capability to generate new and interesting images by learning the real data distribution. We have no control or influence over the images generated by the generator. For instance, let's say our generator is generating human faces; how can we tell the generator to generate a human face with certain features, say big eyes and a sharp nose?

We can't! Because we have no control over the images that are being generated by the generator.

To overcome this, we introduce a small variant of a GAN called a CGAN, which imposes a condition to both the generator and the discriminator. This condition tells the GAN that what image we want our generator to generate. So, both of our components—the discriminator and the generator—act upon this condition.

Let's consider a simple example. Say we are generating handwritten digits using CGAN with the MNIST dataset. Let's assume that we are more focused on generating digit 7 instead of other digits. Now, we need to impose this condition to both of our generators and discriminators. How do we do that?

The generator takes the noise as an input and generates an image. But along with , we also pass an additional input, . This is a one-hot encoded class label. As we are interested in generating digit 7, we set the seventh index to 1 and set all other indices to 0, that is, [0,0,0,0,0,0,0,1,0,0].

We concatenate the latent vector, , and the one-hot encoded conditional variable, , and pass that as an input to the generator. Then, the generator starts generating the digit 7.

What about the discriminator? We know that the discriminator takes image as an input and tells us whether the image is a real or fake image. In CGAN, We want the discriminator to discriminate based on the condition, which means it has to identify whether the generated image is a real digit 7 or a fake digit 7. So, along with passing input , we also pass the conditional variable to the discriminator by concatenating and .

As you can see in the following figure, we are passing and to the generator:

The generator is conditioned on information imposed on . Similarly, along with passing real and fake images to the discriminator, we also pass to the discriminator. So, the generator generates digit 7 and the discriminator learns to discriminate between the real 7 and the fake 7.

We've just learned how to generate a specific digit using CGAN, and yet the applications of CGAN do not end here. Assume we need to generate a digit with a specific width and height. We can also impose this condition on and make the GAN to generate any desired image.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset