With explanations of the math and code

https://miro.medium.com/max/900/1*TKr1dtcNgJCA8uYY1OhmSg.png

GANs, or Generative Adversarial Networks, are a type of neural network architecture that allow neural networks to generate data. In the past few years, they’ve become one of the hottest subfields in deep learning, going from generating fuzzy images of digits to photorealistic images of faces.

Before: fuzzy digits, After: photorealistic faces

https://miro.medium.com/max/231/1*9rP6m-BRPq7O_eJUYzA0Cw.png

https://miro.medium.com/max/2328/1*RyX2xNxTZCKMUW_lErbJVw.png

Variants of GANs have now done insane stuff, like converting images of zebras to horses and vice versa.

https://miro.medium.com/max/1600/1*KjxmJV_DQ84LZjP5u4-dDA.png

I found GANs fascinating, and in an effort to understand them better, I thought that I’d write this article, and in the process of explaining the math and code behind them, understand them better myself.

Here’s a link to a github repo I made for GAN resources:

sarvasvkulpati/Awesome-GAN-Resources

So how do GANs work?

GANs learn a probability distribution of a dataset by pitting two neural networks against each other.

Here’s a great article that explains probability distributions and other concepts for those who aren’t familiar with them:

One model, the generator, acts akin to a painting forger. It tries to create images that look very similar to the dataset. The other model, the discriminator, acts like the police, and tries to detect whether the images generated were fake or not.

https://miro.medium.com/max/1408/1*HKfsgfm-1HLKnXKM7Zseiw.png

What basically happens, is that the forger keeps getting better at making fakes, while the police keep getting better at detecting fakes. Effectively, these two models keep trying to beat each other, until after many iterations, the generator creates images indistinguishable from the real dataset.