Decoding the Science Behind Generative Adversarial Networks
Last Updated on August 16, 2020 by Editorial Team
Author(s): Daksh Trehan
Deep Learning
A dummies guide to GANs that aims at the art ofΒ faking!
Generative adversarial networks(GANs) took the Machine Learning field by storm last year with those impressive fake human-like faces.
Bonus Point* They are basically generated fromΒ nothing.
Irrefutably, GANs implements implicit learning methods where the model learns without the data directly passing through the network, unlike those explicit techniques where weights are learned directly from theΒ data.
Intuition
Okay, suppose in the city of Rio de Janeiro, money forging felonies are increasing so a department is appointed to check in these cases. Detectives are expected to classify the legit ones and fake ones. When the officers correctly classify fake currency they are appreciated and when they make mistakes, feedback is provided by Central Bank. Now, whenever fake currencies are busted, forgers aims at circulating better fake currencies in the market. This is the recursive process when detectives identify fake currencies, the forger learns a better way to develop a more authentic currency, similarly with the admission of more fake currencies in the market the detectives develop an even better strategy to identify fabricated currencies. Both detectives and forgers will become better at what they do by learning from eachΒ other.
This is the basic intuition behindΒ GANs.
In GANs, there are two networks Discriminators (the detectives) and the Generator (the forger). The generator aims at creating fake data and discriminator is expected to bust fake ones. The recursive process makes both generator and discriminator to compete to perform better. Theyβre interdependent on each other as both of them play an essential role in each otherβs learningΒ process.
Another point to ponder is that both networks are constantly learning. Letβs say the discriminator wrongly classified fake data as a real one, that would lead to generator learning that the current developed data is a good one. But, this is technically wrong and will be corrected by discriminator when it gets the feedback from the government about theΒ same.
How GANsΒ learn?
Goal: To generate new data i.e. new images, texts, speech,Β etc.
Generative Modeling
This is the type of modeling that involves learning trends based on given data and try to generate samples that closely resembles the provided data. A very common illustration of Generative modeling can be regarded as, predicting the sequential data.
Generative models follow a joint probability distribution.
The end goal is to get X fromΒ Y.
P(X, Y) can be read as the probability distribution of variables X andΒ Y.
Discriminative Modeling
This type of model generally includes those algorithms that aim at classifying the data from a given trend. Analyzing an image as a cat or a dog in it can be regarded as its bestΒ example.
While discriminative models are the ones that discriminate (classify) the data from a given distribution. Telling if a given picture has a cat or a dog in it, is the simplest example of discriminative modeling.
The end goal is to predict Y fromΒ X.
P(Y|X) can be regarded as βProbability of event Y occurring given event X has occurredβ.
GAN follows Generative modeling and hence it aims at generating P(X,Y)
Model Architecture
Noise
This comes from the random distribution that can be transformed into the required data. By introducing noise, we are making our GAN robust and thus easing its process to βproduce a wide variety of data, sampling from different places in the target distribution.β
Noise should be sampled from Gaussian Distribution.
Data from the Real Distribution
This is the required distribution. We expect GAN to generate data inspired by this distribution with a little help of noiseΒ data.
Generator
This is an essential component of GAN. It focuses on developing data following the trends of distribution.
Generators are required to upsample the input data to generate output data. The upsampling layer is a no weight layer that helps in increasing the spatial size of our inputΒ vector.
The generator creates data that would be classified by discriminator as real or fake. The generator will be fined with more loss if the data generated shares less resemblance with actual data and then using backpropagation it will try to learn from its mistakes to develop a better strategy to fool the discriminator.
Generator training:
- Sample randomΒ noise.
- Produce output using randomΒ noise.
- Analyze loss based on the discriminatorβs classification.
- Backpropagate through both discriminator and generator to get gradients.
- Update weights using gradients.
Goal: To minimize the probability of detecting fake and realΒ data.
Input accepted: RandomΒ noise
Output generated: FakeΒ data
Discriminator
It is just a regular classifier that tries to distinguish real data from fake ones. Its network architecture depends upon the type of data it is implementing upon e.g. it might use RNN for text data, CNN for imageΒ data.
It tries to increase the number of channels thus easing the process to learn more features aboutΒ data.
The discriminator tries to classify the data, it usually ignores the generatorβs loss and just implements a discriminatorβs loss. The discriminator will be fined with more loss if it misclassifies actual data with a fake one and then using backpropagation it will try to learn from its mistakes to develop a better strategy to fool generator.
Discriminator training:
- Classify the input data as real orΒ fake.
- Analyze the loss function for misclassifying.
- Update weights using backpropagation.
Goal: To maximize the probability of detection of real & fakeΒ data.
input: Data (Real+Fake)
output: Probability of data being Real orΒ Fake.
Training ourΒ model
While training our model, both networks must be trained separately. First, the discriminator is trained for several steps and then the training is shifted for generator.
If we try to train both networks simultaneously it would be like aiming for a flying bird and hence increasing our chances ofΒ failure.
As the generator gets better with training, the performance of discriminator gets struck i.e. it becomes difficult for it to classify real and fake data. If the generator succeeds perfectly to achieve its goal i.e. minimizing the probability of detection, the accuracy of discriminator swoops down to 0.5. The downgrade inaccuracy suggests that discriminator has shifted its strategy from statistical to random methods. This further leads to languish Generatorβs accuracy and worsening our modelβs performance.
Type of GANΒ models
Conclusion
Hopefully, this article will help you to understand about Generative Adversarial Networks(GAN) in the best possible way and also assist you to its practical usage.
As always, thank you so much for reading, and please share this article if you found itΒ useful!
Feel free toΒ connect:
LinkedIn ~ https://www.linkedin.com/in/dakshtrehan/
Instagram ~ https://www.instagram.com/_daksh_trehan_/
Github ~ https://github.com/dakshtrehan
Follow for further Machine Learning/ Deep LearningΒ blogs.
Medium ~ https://medium.com/@dakshtrehan
Want to learnΒ more?
Detecting COVID-19 Using DeepΒ Learning
The Inescapable AI Algorithm: TikTok
An insiderβs guide to Cartoonization using MachineΒ Learning
Why are YOU responsible for George Floydβs Murder and Delhi CommunalΒ Riots?
Understanding LSTMβs andΒ GRUβs
Recurrent Neural Network forΒ Dummies
Convolution Neural Network forΒ Dummies
Diving Deep into DeepΒ Learning
Why Choose Random Forest and Not DecisionΒ Trees
Clustering: What it is? When to useΒ it?
Start off your ML Journey with k-Nearest Neighbors
Activation Functions Explained
Parameter Optimization Explained
Determining Perfect Fit for your MLΒ Model
Cheers!
Decoding the Science Behind Generative Adversarial Networks was originally published in Towards AIβββMultidisciplinary Science Journal on Medium, where people are continuing the conversation by highlighting and responding to this story.
Published via Towards AI