Generative Adversarial Networks

Stanley Yoga
4 min readJul 18, 2020

--

Introduction

Generative Adversarial Networks (GANs) are generative models. GANs can generate data on things that never existed before. They learn about the objects that we used for and they can create a new version of those objects.

GANs consist of two components. They have a generator and a discriminator. The generator generates data and the discriminator then assesses those data and tells the generator whether or not those data are likely to be similar. You can tell that the generator is always trying to create data that look like real tables to fools the discriminator in believing that those are real tables.

Generator

The generator is a model that takes an input random noise vector and then it can output generated data. Generator architecture can be dense layer, or maybe Deconvolutional layer as long as they can produce generated data.

Example of generator from DCGAN architecture

Discriminator

You can assume that discriminator is a model that will classify or predict from the real data.

Example of discriminator from DCGAN architecture

How GANs Work

GANs general architecture

First, the generator will take in a random input vector and it will return the generated data.

Next, the generated data will be predicted by the discriminator, together with the real data.

After the discriminator successfully predicted the data, it will return the probability from the data and will be backpropagated to the discriminator and the generator to make them smarter.

It is important to know that all data will be backpropagated to the discriminator, and only generated data will be backpropagated to the generator.

To train the model, we train both the generator and the discriminator together to avoid the generator dominant against the discriminator and vice versa. If one network too strong, it will likely to overfit the other one. For example, if the discriminator was very well trained like it had been trained for a very long time or it was trained separately until a good level, then the generator will have no chance to trick the discriminator.

Type of GANs

FCGAN

It just a simple GAN that consists of only by dense layer and standard sequential models for generation. This architecture is not very powerful. You can use this architecture for such small dataset such as MNIST

DCGAN

DCGAN now involves convolutional and deconvolutional layer for the generator. This model is more powerful at generating images.

Cycle GAN

Cycle GANs are used when you want to convert some images, such as you want to convert horse into zebra, or apple into oranges. It’s called Cycle GAN because of the extra part where it has to reconstruct the original image.

Style GAN

It was developed by NVIDIA to generate super-realistic faces. You can find and use their pretrained model here.

There are still many kinds of GANs, but it will be overkill if we discuss all of it in this section.

Application

Generating Images

Generated Images from MNIST Dataset

As previously explained in Style GAN, GAN can produce some useful images for the dataset. You can use it to upsampling your data when you have imbalanced dataset.

Image Modification

Cycle GAN Image Modification

From the picture above, GAN, precisely Cycle GAN can convert objects from images. It can convert orange to apple, zebra to horse, and vice versa. Not only the object, but it can change the image environment too. Like in that picture, GANs learn that zebra rarely stand near the beach, so they change the environment to more likely savanna.

Super Resolution

Super Resolution using SRGAN

As you can see from the image above, GAN, precisely SRGAN, works really well to increase the resolution of the images compared with another algorithm. Apart from its functionality, SRGAN is pretty heavy. You need a high-end NVIDIA GPUs with at least 11GB of DRAM.

Photo Realistic Images

GAN generate images from drawing

For me, this is the most interesting application from GANs. It can produce some real images from just only drawing lines. It uses Conditional Adversarial Networks to generate the images. If you’re curious, you can read the paper here.

Conclusion

Generative Adversarial Networks are powerful architecture in deep learning. It consists of two main parts, Generator and Discriminator. They need to be trained together and can’t be dominant against others, because it can overfit the model.

References

[1] Ian J. Goodfellow. (June 10, 2014). Generative Adversarial Networks. https://arxiv.org/abs/1406.2661

[2] Jason Brownies. (July 19, 2019). A Gentle Introduction to Generative Adversarial Networks (GANs). https://machinelearningmastery.com/what-are-generative-adversarial-networks-gans/

[3] Chanchana Sornsoontorn. (January 28, 2017). How do GANs intuitively work. https://hackernoon.com/how-do-gans-intuitively-work-2dda07f247a1

--

--