How GAN can help us to improve face image data(with demo)
“Generative Adversarial Network— the most interesting idea in the last ten years in machine learning” by Yann LeCun, VP & Chief AI Scientist at Facebook, Godfather of AI.
GAN – What is Generative Adversarial Networks ?
GANs are unsupervised deep learning techniques. In the AI world GAN(Generative Adversarial Networks) is the best way to improve quality of our image data, it also use for image restoration. GAN leads us to thousands of GAN research papers written in recent years. The main focus for GAN is to generate data from scratch, mostly images but other domains including music have been done.
Generative modeling is an unsupervised learning task in machine learning that involves automatically discovering and learning the regularities or patterns in input data in such a way that the model can be used to generate or output new examples that plausibly could have been drawn from the original dataset.
Just like the example below, it restoring a face from old blurry image.
What is Generator and discriminator in GAN?
GAN is implemented using two neural networks: Generator and Discriminator. These two models compete with each other in a form of a game setting. The GAN model would be trained on real data and data generated by the generator. The generator part of a GAN learns to create fake data by incorporating feedback from the discriminator. It learns to make the discriminator classify its output as real.
A Generator in GANs is a neural network that creates fake data to be trained on the discriminator. Generator model takes a fixed-length random vector as input and generates a sample in the domain. The main aim of the Generator is to make the discriminator classify its output as real.
Examples of generative models:
Latent Dirichlet Allocation
Gaussian Mixture Model
The discriminator model takes an example from the domain as input (real or generated) and predicts a binary class label of real or fake (generated). The generated examples are output by the generator model.
The real example comes from the training dataset, discriminator is a normal classification model
How GFPGAN Can Help to improve image quality(Demo)
Below is the demo on my own image, applying GFP(generative facial prior) to re-generate clean image, Using the python to show the demo. If anyone is interested to test it on own data you can refer my colab notebook or open-source github link of official GFPGAN’s.
Import and download all the necessary libraries and dependencies.
!git clone https://github.com/TencentARC/GFPGAN.git%cd GFPGAN
!pip install basicsr
!pip install facexlib
!pip install -r requirements.txt
!pip install realesrgan
#Version model 1.3 for demo
!wget https://github.com/TencentARC/GFPGAN/releases/download/v1.3.0/GFPGANv1.3.pth -P experiments/pretrained_models
Import your own image data. Here i’m using my own photo for demo. You can find the image upload code in notebook.
As you can see below one, the image is bit noisy and blur.
Now, below command will help to train the model.
!rm -rf results
!python inference_gfpgan.py -i inputs/upload -o results -v 1.3 -s 2 –bg_upsampler realesrgan
Output image visualization.
You can see the result 🙂
How GAN can play a major role in data world for data generate and improvising.
Applications of GAN
1. DCGANs can help you to train images of cartoon characters for generating faces of anime characters as well as Pokemon characters.
2. GANs can build realistic images from textual descriptions of objects like birds, humans, and other animals.
This was brief about GAN networks, you would have understood the basics of GANs and how it works.
Below are some GAN use cases for business:
- GAN can use for improve document images like, Aadhar card, Pan card etc.
- In the banking and financial domain GAN can play a immense role to identify fake and real document images.
- In animation industry GAN can help to generate new faces.
HAPPY LEARNING 🙂
My notebook link