1
Lecture 16:
Generative Adversarial Networks
Erik Learned-Miller and TAs�Adapted from slides of Fei-Fei Li & Justin Johnson & Serena Yeung
Lecture 16 -
Oct 27, 2020
Erik Learned-Miller and TAs�Adapted from slides of Fei-Fei Li & Justin Johnson & Serena Yeung
Lecture 16 -
Nov 21, 2019
Generative Adversarial Networks
2
Ian Goodfellow et al., “Generative Adversarial Nets”, NIPS 2014
Problem: Want to sample from complex, high-dimensional training distribution. No direct way to do this!
Solution: Sample from a simple distribution, e.g. random noise. Learn transformation to training distribution.
Q: What can we use to represent this complex transformation?
Erik Learned-Miller and TAs�Adapted from slides of Fei-Fei Li & Justin Johnson & Serena Yeung
Lecture 16 -
Nov 21, 2019
Generative Adversarial Networks
3
Problem: Want to sample from complex, high-dimensional training distribution. No direct way to do this!
Solution: Sample from a simple distribution, e.g. random noise. Learn transformation to training distribution.
z
Input: Random noise
Generator Network
Output: Sample from training distribution
Q: What can we use to represent this complex transformation?
A: A neural network!
Ian Goodfellow et al., “Generative Adversarial Nets”, NIPS 2014
Erik Learned-Miller and TAs�Adapted from slides of Fei-Fei Li & Justin Johnson & Serena Yeung
Lecture 16 -
Nov 21, 2019
Training GANs: Two-player game
4
Generator network: try to fool the discriminator by generating real-looking images
Discriminator network: try to distinguish between real and fake images
Ian Goodfellow et al., “Generative Adversarial Nets”, NIPS 2014
Erik Learned-Miller and TAs�Adapted from slides of Fei-Fei Li & Justin Johnson & Serena Yeung
Lecture 16 -
Nov 21, 2019
Training GANs: Two-player game
5
Generator network: try to fool the discriminator by generating real-looking images
Discriminator network: try to distinguish between real and fake images
z
Random noise
Generator Network
Discriminator Network
Fake Images
(from generator)
Real Images
(from training set)
Real or Fake
Ian Goodfellow et al., “Generative Adversarial Nets”, NIPS 2014
Fake and real images copyright Emily Denton et al. 2015. Reproduced with permission.
Erik Learned-Miller and TAs�Adapted from slides of Fei-Fei Li & Justin Johnson & Serena Yeung
Lecture 16 -
Nov 21, 2019
Training GANs: Two-player game
6
Generator network: try to fool the discriminator by generating real-looking images
Discriminator network: try to distinguish between real and fake images
Train jointly in minimax game
Minimax objective function:
Ian Goodfellow et al., “Generative Adversarial Nets”, NIPS 2014
Erik Learned-Miller and TAs�Adapted from slides of Fei-Fei Li & Justin Johnson & Serena Yeung
Lecture 16 -
Nov 21, 2019
Minimax objectives: Saddle points
7
Train jointly in minimax game
Minimax objective function:
Erik Learned-Miller and TAs�Adapted from slides of Fei-Fei Li & Justin Johnson & Serena Yeung
Lecture 16 -
Nov 21, 2019
Training GANs: Two-player game
8
Generator network: try to fool the discriminator by generating real-looking images
Discriminator network: try to distinguish between real and fake images
Train jointly in minimax game
Minimax objective function:
Ian Goodfellow et al., “Generative Adversarial Nets”, NIPS 2014
Erik Learned-Miller and TAs�Adapted from slides of Fei-Fei Li & Justin Johnson & Serena Yeung
Lecture 16 -
Nov 21, 2019
Training GANs: Two-player game
9
Generator network: try to fool the discriminator by generating real-looking images
Discriminator network: try to distinguish between real and fake images
Train jointly in minimax game
Minimax objective function:
Discriminator output for real data x
Discriminator output for generated fake data G(z)
Discriminator outputs likelihood in (0,1) of real image
Ian Goodfellow et al., “Generative Adversarial Nets”, NIPS 2014
Should be 1 for real data x�
Should be 0 for fake data z.
Erik Learned-Miller and TAs�Adapted from slides of Fei-Fei Li & Justin Johnson & Serena Yeung
Lecture 16 -
Nov 21, 2019
Training GANs: Two-player game
10
Generator network: try to fool the discriminator by generating real-looking images
Discriminator network: try to distinguish between real and fake images
Train jointly in minimax game
Minimax objective function:
Discriminator output for real data x
Discriminator output for generated fake data G(z)
Discriminator outputs likelihood in (0,1) of real image
Ian Goodfellow et al., “Generative Adversarial Nets”, NIPS 2014
Erik Learned-Miller and TAs�Adapted from slides of Fei-Fei Li & Justin Johnson & Serena Yeung
Lecture 16 -
Nov 21, 2019
Training GANs: Two-player game
11
Minimax objective function:
Alternate between:
2. Gradient descent on generator
Ian Goodfellow et al., “Generative Adversarial Nets”, NIPS 2014
Erik Learned-Miller and TAs�Adapted from slides of Fei-Fei Li & Justin Johnson & Serena Yeung
Lecture 16 -
Nov 21, 2019
Training GANs: Two-player game
12
Minimax objective function:
Alternate between:
2. Gradient descent on generator
In practice, optimizing this generator objective does not work well!
Ian Goodfellow et al., “Generative Adversarial Nets”, NIPS 2014
When sample is likely fake, want to learn from it to improve generator. But gradient in this region is relatively flat!
Gradient signal dominated by region where sample is already good
Erik Learned-Miller and TAs�Adapted from slides of Fei-Fei Li & Justin Johnson & Serena Yeung
Lecture 16 -
Nov 21, 2019
Training GANs: Two-player game
13
Minimax objective function:
Alternate between:
2. Instead: Gradient ascent on generator, different objective
Instead of minimizing likelihood of discriminator being correct, now maximize likelihood of discriminator being wrong.
Same objective of fooling discriminator, but now higher gradient signal for bad samples => works much better! Standard in practice.
Ian Goodfellow et al., “Generative Adversarial Nets”, NIPS 2014
High gradient signal
Low gradient signal
Erik Learned-Miller and TAs�Adapted from slides of Fei-Fei Li & Justin Johnson & Serena Yeung
Lecture 16 -
Nov 21, 2019
Training GANs: Two-player game
14
Minimax objective function:
Alternate between:
2. Instead: Gradient ascent on generator, different objective
Instead of minimizing likelihood of discriminator being correct, now maximize likelihood of discriminator being wrong.
Same objective of fooling discriminator, but now higher gradient signal for bad samples => works much better! Standard in practice.
Ian Goodfellow et al., “Generative Adversarial Nets”, NIPS 2014
High gradient signal
Low gradient signal
Aside: Jointly training two networks is challenging, can be unstable. Choosing objectives with better loss landscapes helps training, is an active area of research.
Erik Learned-Miller and TAs�Adapted from slides of Fei-Fei Li & Justin Johnson & Serena Yeung
Lecture 16 -
Nov 21, 2019
Training GANs: Two-player game
15
Putting it together: GAN training algorithm
Ian Goodfellow et al., “Generative Adversarial Nets”, NIPS 2014
Erik Learned-Miller and TAs�Adapted from slides of Fei-Fei Li & Justin Johnson & Serena Yeung
Lecture 16 -
Nov 21, 2019
Training GANs: Two-player game
16
Putting it together: GAN training algorithm
Some find k=1 more stable, others use k > 1, no best rule.
Recent work (e.g. Wasserstein GAN) alleviates this problem, better stability!
Ian Goodfellow et al., “Generative Adversarial Nets”, NIPS 2014
Erik Learned-Miller and TAs�Adapted from slides of Fei-Fei Li & Justin Johnson & Serena Yeung
Lecture 16 -
Nov 21, 2019
Training GANs: Two-player game
17
Generator network: try to fool the discriminator by generating real-looking images
Discriminator network: try to distinguish between real and fake images
z
Random noise
Generator Network
Discriminator Network
Fake Images
(from generator)
Real Images
(from training set)
Real or Fake
After training, use generator network to generate new images
Ian Goodfellow et al., “Generative Adversarial Nets”, NIPS 2014
Fake and real images copyright Emily Denton et al. 2015. Reproduced with permission.
Erik Learned-Miller and TAs�Adapted from slides of Fei-Fei Li & Justin Johnson & Serena Yeung
Lecture 16 -
Nov 21, 2019
Generative Adversarial Nets
18
Nearest neighbor from training set
Generated samples
Ian Goodfellow et al., “Generative Adversarial Nets”, NIPS 2014
Figures copyright Ian Goodfellow et al., 2014. Reproduced with permission.
Erik Learned-Miller and TAs�Adapted from slides of Fei-Fei Li & Justin Johnson & Serena Yeung
Lecture 16 -
Nov 21, 2019
Generative Adversarial Nets
19
Nearest neighbor from training set
Generated samples (CIFAR-10)
Ian Goodfellow et al., “Generative Adversarial Nets”, NIPS 2014
Figures copyright Ian Goodfellow et al., 2014. Reproduced with permission.
Erik Learned-Miller and TAs�Adapted from slides of Fei-Fei Li & Justin Johnson & Serena Yeung
Lecture 16 -
Nov 21, 2019
Generative Adversarial Nets: Convolutional Architectures
20
Radford et al, “Unsupervised Representation Learning with Deep Convolutional Generative Adversarial Networks”, ICLR 2016
Generator is an upsampling network with fractionally-strided convolutions
Discriminator is a convolutional network
Erik Learned-Miller and TAs�Adapted from slides of Fei-Fei Li & Justin Johnson & Serena Yeung
Lecture 16 -
Nov 21, 2019
Generative Adversarial Nets: Convolutional Architectures
21
Radford et al, “Unsupervised Representation Learning with Deep Convolutional Generative Adversarial Networks”, ICLR 2016
Generator
Erik Learned-Miller and TAs�Adapted from slides of Fei-Fei Li & Justin Johnson & Serena Yeung
Lecture 16 -
Nov 21, 2019
Generative Adversarial Nets: Convolutional Architectures
22
Radford et al,� ICLR 2016
Samples from the model look much better!
Erik Learned-Miller and TAs�Adapted from slides of Fei-Fei Li & Justin Johnson & Serena Yeung
Lecture 16 -
Nov 21, 2019
Generative Adversarial Nets: Convolutional Architectures
23
Radford et al,� ICLR 2016
Interpolating between random �points in latent space
Erik Learned-Miller and TAs�Adapted from slides of Fei-Fei Li & Justin Johnson & Serena Yeung
Lecture 16 -
Nov 21, 2019
Generative Adversarial Nets: Interpretable Vector Math
24
Smiling woman
Neutral woman
Neutral man
Samples �from the �model
Radford et al, ICLR 2016
Erik Learned-Miller and TAs�Adapted from slides of Fei-Fei Li & Justin Johnson & Serena Yeung
Lecture 16 -
Nov 21, 2019
Generative Adversarial Nets: Interpretable Vector Math
25
Smiling woman
Neutral woman
Neutral man
Samples �from the �model
Average Z
vectors, do arithmetic
Radford et al, ICLR 2016
Erik Learned-Miller and TAs�Adapted from slides of Fei-Fei Li & Justin Johnson & Serena Yeung
Lecture 16 -
Nov 21, 2019
Generative Adversarial Nets: Interpretable Vector Math
26
Smiling woman
Neutral woman
Neutral man
Smiling Man
Samples �from the �model
Average Z
vectors, do arithmetic
Radford et al, ICLR 2016
Erik Learned-Miller and TAs�Adapted from slides of Fei-Fei Li & Justin Johnson & Serena Yeung
Lecture 16 -
Nov 21, 2019
Generative Adversarial Nets: Interpretable Vector Math
27
Radford et al, �ICLR 2016
Glasses man
No glasses man
No glasses woman
Erik Learned-Miller and TAs�Adapted from slides of Fei-Fei Li & Justin Johnson & Serena Yeung
Lecture 16 -
Nov 21, 2019
Generative Adversarial Nets: Interpretable Vector Math
28
Glasses man
No glasses man
No glasses woman
Woman with glasses
Radford et al, �ICLR 2016
Erik Learned-Miller and TAs�Adapted from slides of Fei-Fei Li & Justin Johnson & Serena Yeung
Lecture 16 -
Nov 21, 2019
“The GAN Zoo”
2017: Explosion of GANs
“The GAN Zoo”
29
https://github.com/hindupuravinash/the-gan-zoo
Erik Learned-Miller and TAs�Adapted from slides of Fei-Fei Li & Justin Johnson & Serena Yeung
Lecture 16 -
Nov 21, 2019
2017: Explosion of GANs
“The GAN Zoo”
30
https://github.com/hindupuravinash/the-gan-zoo
See also: https://github.com/soumith/ganhacks for tips and tricks for trainings GANs
Erik Learned-Miller and TAs�Adapted from slides of Fei-Fei Li & Justin Johnson & Serena Yeung
Lecture 16 -
Nov 21, 2019
2017: Explosion of GANs
31
Better training and generation
LSGAN, Zhu 2017.
Wasserstein GAN, Arjovsky 2017.
Improved Wasserstein GAN, Gulrajani 2017.
Progressive GAN, Karras 2018.
Erik Learned-Miller and TAs�Adapted from slides of Fei-Fei Li & Justin Johnson & Serena Yeung
Lecture 16 -
Nov 21, 2019
2017: Explosion of GANs
32
CycleGAN. Zhu et al. 2017.
Source->Target domain transfer
Many GAN applications
Pix2pix. Isola 2017. Many examples at https://phillipi.github.io/pix2pix/
Reed et al. 2017.
Text -> Image Synthesis
Erik Learned-Miller and TAs�Adapted from slides of Fei-Fei Li & Justin Johnson & Serena Yeung
Lecture 16 -
Nov 21, 2019
GANs
33
Take game-theoretic approach: learn to generate from training distribution through 2-player game
Pros:
Cons:
Active areas of research:
Erik Learned-Miller and TAs�Adapted from slides of Fei-Fei Li & Justin Johnson & Serena Yeung
Lecture 16 -
Nov 21, 2019