Generative Adversarial Networks (GANs)
By: Jatin Gupta
Tags: Neural Networks, Gans, Keras, Machine Learning, Deep Learning

INTRODUCTION

GANs stands for the Generative Adversarial Networks designed by Ian Good fellow along with his colleagues at University of Montreal, in the year 2014.

Generative adversarial networks (GANs) are basically architecture based algorithmic that in use by the two neural networks in pitting one against the other in order to generate new synthetic instances of data that we can pass for real data. GANs are widely used for image generation, video generation and voice generation.

The core idea of a GANs is based on the ‘indirect training’ through the discriminator which itself is also being updated dynamically. This means that the generator is not trained to minimize the distance to a specific image, but rather to fool the discriminator. This enables the model to learn in an unsupervised manner.

How Generative Adversarial Networks(GANs) Works

One special kind of neural network called the generator, it generates new data instances while the second kind of neural network is discriminator basically it evaluates the authenticity level i.e. the discriminator decides whether each instance of data that it to be review belongs to the actual training dataset or some other. The goal of the discriminator is to shown an instance from the true MNIST dataset, is to recognize those that are authentic.

While the generator creates a new images that will be passes through the discriminator. It does so in the hopes that they, too, will be deemed authentic, even though they are fake. The goal of the generator is to generate passable hand-written digits: to lie without being caught. The goal of the discriminator is to identify images coming from the generator as fake.

The steps GANs takes into play are as follows:

Generator takes the random numbers and returns as a image.

Generated image is fed in to the discriminator side by side a stream of images taken from the actual ground-truth dataset.

Discriminator takes both real as well as fake images and returns the probabilities i.e. a number between 0 and 1, with 1 representing as prediction of authenticity and 0 as representing fake.

Fig1.1 Flow Diagram of GANs

Different Types Of GANs

TF-GAN

TF-GAN stands for the tensor flow GANs. This is a open-source light weight python library developed by the Google research AI for better and easy implementation GANs.

This helps us in provides a well-developed infrastructure to train and evaluate the GANs along with effectively tested along with loss functions and evaluation metrics also provides a simple function that a user can apply on his own data without the code implementation from scratch.

Torch-GAN

This is a Py Torch based framework for better understanding and writing in a short easy way to understand codes for developing GANs. This library consists of various network along with utilities for the implementation. This imitates the design of GANs through simple API and also allows the customizing of components when required.

This is having multiple components or models like generator, discriminator, evaluate metrics and the loss function.

Fig 1.2 Overview of Torch-GANs

Deep Convolutional GANs (DCGANs)

DCGANs generally used for the improvements of GANs , more stable and also generate higher quality images. In this normalization of batch is done in both networks i.e. generator as well as discriminator network and can be used for style transfer.

Lets suppose we have handbags dataset to generate shoes in the same style as the handbags.

Conditional GANs (C-GANs)

They are use to extra label the information and produce the result in better quality and also control how the new generated images will look and make the model learn to produce better images by using the exploiting of information fed into the model.

Fig1.3 Conditional GANs

Stack GANs

The author propose a Stacked Generative Adversarial Networks (Stack GANs) to generate the high quality 256x256 realistic images conditioned on text descriptions. He decompose the hard problem into manageable sub-problems through the refinement process. With the help of Stack GANs suggested a solution of problem for synthesizing high quality images from text descriptions.

Fig1.4 Synthesis of Images using Stack GANs

The First stage represent primitive shape and colors of object based on the given text description yielding low-resolution images. While the Second stage takes first stage results, text descriptions as inputs and generates high-resolution images details as output.

Key Points While Training a GANs

Generator and Discriminator plays a very important role in training a GANs. When we use generator in training we have to keep the discriminator as constant and when we use discriminator in training we keep generator as constant. They both play a static adversary against each other.

If the Discriminator is pre training against the particular dataset before start the training part the generator will make a clearer gradient against that. Each part in GANs plays an important role and can over power the other.GANs take very long time to train, on a single GPU it might take hours, and on a single CPU more than a day required for training.

If Discriminator is good it will return values very close to 0 or 1 on the other hand generator face lots of problem to read the gradient. While if the generator is good it will persistently exploit weaknesses in the discriminator that will lead to false negatives.

Code Implementation

Here is an example of GANs code.

Applications of GANs

There are multiple application of GANs are follows:

Text to Image Generation

Using a special type of GANs it can generate different types of images from a text description.

Fig 1.5

Image to Image Translation

We can also feed the sketch images to the GANs to produce the real images as output.

Fig 1.6

Increasing Resolution of an image

It also fed the low resolution images and helps to produce the high resolution images.

Fig 1.7

Semantic Image to Photo Translation

It helps to demonstrate the use of GANs to generate photorealistic images along with given a semantic image/ sketch as input.

Fig 1.8

Photos to Emojis

GANs also play an important role in image translation i.e. from one domain to other domain from street numbers to MNIST handwritten digits, photographs to emojis or small cartoon faces.

Fig 1.9

Advantage of GANs

In GANs there is no code way of implementing the art computer vision technology only a simple JSON file is required to define the particular architecture.

Best about GANs is there is no need to write the training code from scratch as the framework will take care of it.

GANs also provide the multi library support such as PyTorch, Tenserflow, and Keras etc.

Summary

In this article we have gone through about the Generative Adversarial Networks (GANs) in details we discuss almost every thing for good understanding about GANs. Hope You Like It…