Generative Adversarial Networks, what are they and how do they work?

Generative Adversarial Networks

Generative Adversarial Networks

If you’ve ever used an advanced filter on a picture before sharing it on Instagram or Facebook, chances are you used artificial intelligence and didn’t even know it. A great example of this is a mobile app called Prisma that applies amazing filters to your pictures based on styles.  With this app, you could input this picture and apply this filter to make it look like this:

Prisma Filter Example
Prisma Filter Example

It could be doing this by using a Generative Adversarial Network, a neural network that has been trained specifically on this style of picture. Here is a simple breakdown of how a GAN works.

The Generator – its job is to generate things, at first very randomly. The generator submits these things to the Discriminator to be graded.  The generator will perform very poorly in the beginning, but using the feedback from the Discriminator, it will slowly get better and better.

Generator and Discriminator
Generator and Discriminator

The Discriminator – its job is to grade the things from the generator.  But first, it is fed things that are known to be true so it knows what a good thing really looks like. Once it has this “ground truth”, it will have the ability to tell the generator if the output is good or bad.

Discriminator and Ground Truth
Discriminator and Ground Truth

In reality, this interaction between the generator and discriminator will happen thousands of times, all depending on how long it takes for it to learn enough to create a good result.

Here is an example of a GAN I trained using batches of pictures of vehicles and animals from the CIFAR-10 dataset.

Generator output after 1st round of training
Generator output after 1st round of training

After the 1st round of training, it looks like gibberish and random noise.

Generator output after 20th round of training
Generator output after 20th round of training

After the 20th round of testing, it’s starting to look like actual things.  But still, if you look closely enough, it’s not quite there.  Compare that to a real sample of the training data below:

Real training sample data
Real training sample data

Pretty close right? I hope these examples help you to understand the basic intuition of how GANs work. The exciting thing about these types of neural networks is that they actually generate output versus answering a problem. Compare that to a neural net that can identify objects, make recommendations on videos based on what you’ve watched, or predict stock prices from previous stock price history.

Sources
https://prisma-ai.com/
http://www.cs.toronto.edu/~kriz/cifar.html
https://www.udemy.com/computer-vision-a-z/

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.