WGAN-GP
Alex Lau
Hong Kong Machine Learning Meetup
17/07/2019
Table of Content
What is GAN?
What is GAN?
| Discriminator | Generator |
Input | Data (real / fake) | Data (prior noise) |
Output | Probability (0-1) ~1 means high confidence the input data belong to real data | Fake data |
Purpose (Functional) | Classify fake data and real data correctly | Fool discriminator to mistake fake data as real data |
Purpose (Math) | Maximise the chance of distinguishing real data as real data | Minimise the chance of classifying fake data as fake data |
How do we measure distribution similarity?
Cost Function of GAN
D stands for Discriminator network
G stands for Generator network
First term considers sample from real data
Second term consider sample from fake data
Cost Function of GAN
D stands for Discriminator network
G stands for Generator network
D(x) should output ~1 when input are real data
For sample from real data, discriminator aims to higher the chance of classifying them as real data
D(x) should output ~0 when input are generated data
For fake data, discriminator aims to higher the chance of classifying them as fake data
Cost Function of GAN
D stands for Discriminator network
G stands for Generator network
G(.) should fool D(.) so as to output ~1
Generator aims to produce data so as to higher the chance of discriminator classifying them as real data
Cost Function of GAN
D stands for Discriminator network
G stands for Generator network
Optimizing the cost function is equivalent to minimizing JS divergence
Pain-point when training GAN
Cost Function not Smooth
GAN uses JS divergence (closely related to KL divergence) as measurement of distribution similarity
Both JS divergence and KL divergence gives non-smooth surface when two distribution has a disjoint support
Vanishing Gradient
If we apply KL/ JS divergence on the cost function, it easily leads to vanishing gradient
(Vanishing gradient is an issue when optimise comes to a flat surface...
It makes neural network learn almost nothing for each iteration)
Mode Collapse
Generated data stuck in a small space with extremely low variety
Equilibrium is reached but the model is bad...
Lack of Indicative Metrics for Training Performance
Lack of Indicative Metrics for Training Performance
What is WGAN-GP?
Introducing Wasserstein Distance
How Wasserstein Distance Measure Similarity?
v.s.
How Wasserstein Distance Measure Similarity?
Wasserstein Distance
= ⅓ * (5-1) + ⅓ * (6-2) + ⅓ * (7-3) = 4
| 5 | 6 | 7 |
1 | 1/3 | 0 | 0 |
2 | 0 | 1/3 | 0 |
3 | 0 | 0 | 1/3 |
However, WD is Hard to Compute ….
Original form is VERY hard to compute
With math magic, it can be expressed in another form that is easier to compute (under a certain constraint…)
Apply gradient penalty to enforce the constraint (help avoid gradient exploding/ vanishing)
(Where D(x) is 1-Lipschitz function)
I.e. differentiable + derivative norm <= 1
How WGAN-GP Can Help?
Smoothen the Function to be Optimised
Avoid Mode Collapse
Loss Curve More indicative of Training Performance
Loss Curve More indicative of Training Performance
WGANGP v.s. GAN
GAN v.s. WGAN-GP in Algorithm
WGAN-GP
GAN
GAN v.s. WGAN-GP in Algorithm
WGAN-GP
GAN
What are somethings in common?
High-level structure
GAN v.s. WGAN-GP in Algorithm
WGAN-GP
GAN
What are somethings in common?
Generator input
GAN v.s. WGAN-GP in Algorithm
WGAN-GP
GAN
What are somethings in common?
Number of training for discriminator
GAN v.s. WGAN-GP in Algorithm
WGAN-GP
GAN
What are the differences?
Number of training for discriminator
GAN v.s. WGAN-GP in Algorithm
WGAN-GP
GAN
What are the differences?
Optimizer
GAN v.s. WGAN-GP in Algorithm
WGAN-GP
GAN
What are the differences?
Discriminator output
Discriminator output probability (0 - 1)
Sigmoid as activation function
Critic output any real number
Sigmoid is removed
GAN v.s. WGAN-GP in Algorithm
WGAN-GP
GAN
What are the differences?
Cost Function
Applications of WGAN-GP
Image Inpainting (Yu et al, 2018)
Image Inpainting (Yu et al, 2018)
Recovered by WGAN-GP
Recovered by GAN
Image Inpainting (Yu et al, 2018)
You can try their demo: http://jiahuiyu.com/deepfill/
Image Coloring
DeOldify: https://github.com/jantic/DeOldify
Reference
Open to Project Collaboration
Proposed Projects