Analytics Vidhya
Published in

Analytics Vidhya

GAN (Generative Adversarial Networks)

GANs are an approach to generative modeling using deep learning methods.

Lets understand GANs using a simple example.

Their are fake currencies and real currencies. Police is able to distinguish between fake and real ones and gives feedback to fake currencies generator and it tries to do better next time. I know it’s bit confusing but after a few moments I am sure you will get it.

The training of model is done in two steps.

Step 1:

Police that is our discriminator is trained and it distinguishes between fake and real notes.

Step 2:

Our generator of fake notes is trained and discriminator layer is frozen.

Let’s look at the code and understand better.

Here I have only discussed only the main part the full code repo is available at last.

We just initialized the variables.

This is our generator model. It will give output and we can resize it in 28*28 image. You try a different number of layers with different number of preceptrons.

Here we have our discriminator model.

This is our Step 2 were we froze our discriminator model.

As you can observe we first train our discriminator(police) and then freeze it and train out generator. you can observe that they mutually helps each other to preform better and more better. Just go threw the code and once again read the article I am sure you will get it. It will take some time in first go but let it settle.

Few tips to note-

  • Noise should be sample of Gaussian Distribution.
  • LeakyRelu
This is the output after 50 epochs and these digits are generated by our machine. Is it fascinating.

You can have better quality of images by using DCGANs, but we will continue this some other day.

GitHub repo link — https://github.com/tjjain/GAN

I have tried to explain in most easy language as possible. I just started with writing all these stuff it will be great if you can tell me where I can improve to provide better content.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Tanmaya Jain

Tanmaya Jain

14 Followers

I am BTech student at Delhi Technological University and having deep interest in ML/DL and data science.