You are on page 1of 133

Lecture 13:

Generative Models

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 1 May 18, 2017
Administrative

Midterm grades released on Gradescope this week

A3 due next Friday, 5/26

HyperQuest deadline extended to Sunday 5/21, 11:59pm

Poster session is June 6

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 2 May 18, 2017
Overview

● Unsupervised Learning

● Generative Models
○ PixelRNN and PixelCNN
○ Variational Autoencoders (VAE)
○ Generative Adversarial Networks (GAN)

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 3 May 18, 2017
Supervised vs Unsupervised Learning
Supervised Learning

Data: (x, y)
x is data, y is label

Goal: Learn a function to map x -> y

Examples: Classification,
regression, object detection,
semantic segmentation, image
captioning, etc.

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 4 May 18, 2017
Supervised vs Unsupervised Learning
Supervised Learning

Data: (x, y)
x is data, y is label
Cat
Goal: Learn a function to map x -> y

Examples: Classification,
regression, object detection, Classification
semantic segmentation, image
captioning, etc.
This image is CC0 public domain

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 5 May 18, 2017
Supervised vs Unsupervised Learning
Supervised Learning

Data: (x, y)
x is data, y is label

Goal: Learn a function to map x -> y

Examples: Classification, DOG, DOG, CAT


regression, object detection,
semantic segmentation, image Object Detection
captioning, etc.
This image is CC0 public domain

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 6 May 18, 2017
Supervised vs Unsupervised Learning
Supervised Learning

Data: (x, y)
x is data, y is label

Goal: Learn a function to map x -> y


GRASS, CAT,
Examples: Classification,
TREE, SKY
regression, object detection,
semantic segmentation, image Semantic Segmentation
captioning, etc.

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 7 May 18, 2017
Supervised vs Unsupervised Learning
Supervised Learning

Data: (x, y)
x is data, y is label

Goal: Learn a function to map x -> y


A cat sitting on a suitcase on the floor
Examples: Classification,
regression, object detection,
Image captioning
semantic segmentation, image
captioning, etc. Caption generated using neuraltalk2
Image is CC0 Public domain.

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 8 May 18, 2017
Supervised vs Unsupervised Learning
Unsupervised Learning

Data: x
Just data, no labels!

Goal: Learn some underlying


hidden structure of the data

Examples: Clustering,
dimensionality reduction, feature
learning, density estimation, etc.

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 9 May 18, 2017
Supervised vs Unsupervised Learning
Unsupervised Learning

Data: x
Just data, no labels!

Goal: Learn some underlying


hidden structure of the data

Examples: Clustering,
K-means clustering
dimensionality reduction, feature
learning, density estimation, etc.
This image is CC0 public domain

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 10 May 18, 2017
Supervised vs Unsupervised Learning
Unsupervised Learning

Data: x
Just data, no labels!

Goal: Learn some underlying


hidden structure of the data 3-d 2-d

Examples: Clustering, Principal Component Analysis


dimensionality reduction, feature (Dimensionality reduction)
learning, density estimation, etc.
This image from Matthias Scholz
is CC0 public domain

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 11 May 18, 2017
Supervised vs Unsupervised Learning
Unsupervised Learning

Data: x
Just data, no labels!

Goal: Learn some underlying


hidden structure of the data

Examples: Clustering,
dimensionality reduction, feature Autoencoders
learning, density estimation, etc. (Feature learning)

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 12 May 18, 2017
Supervised vs Unsupervised Learning
Unsupervised Learning

Data: x Figure copyright Ian Goodfellow, 2016. Reproduced with permission.

Just data, no labels! 1-d density estimation

Goal: Learn some underlying


hidden structure of the data

Examples: Clustering,
dimensionality reduction, feature 2-d density estimation
learning, density estimation, etc.
2-d density images left and right
are CC0 public domain

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 13 May 18, 2017
Supervised vs Unsupervised Learning
Supervised Learning Unsupervised Learning

Data: (x, y) Data: x


x is data, y is label Just data, no labels!

Goal: Learn a function to map x -> y Goal: Learn some underlying


hidden structure of the data
Examples: Classification,
regression, object detection, Examples: Clustering,
semantic segmentation, image dimensionality reduction, feature
captioning, etc. learning, density estimation, etc.

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 14 May 18, 2017
Supervised vs Unsupervised Learning
Supervised Learning Unsupervised Learning
Training data is cheap
Data: (x, y) Data: x Holy grail: Solve
x is data, y is label Just data, no labels! unsupervised learning
=> understand structure
of visual world
Goal: Learn a function to map x -> y Goal: Learn some underlying
hidden structure of the data
Examples: Classification,
regression, object detection, Examples: Clustering,
semantic segmentation, image dimensionality reduction, feature
captioning, etc. learning, density estimation, etc.

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 15 May 18, 2017
Generative Models
Given training data, generate new samples from same distribution

Training data ~ pdata(x) Generated samples ~ pmodel(x)

Want to learn pmodel(x) similar to pdata(x)

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 16 May 18, 2017
Generative Models
Given training data, generate new samples from same distribution

Training data ~ pdata(x) Generated samples ~ pmodel(x)

Want to learn pmodel(x) similar to pdata(x)

Addresses density estimation, a core problem in unsupervised learning


Several flavors:
- Explicit density estimation: explicitly define and solve for pmodel(x)
- Implicit density estimation: learn model that can sample from pmodel(x) w/o explicitly defining it

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 17 May 18, 2017
Why Generative Models?
- Realistic samples for artwork, super-resolution, colorization, etc.

- Generative models of time-series data can be used for simulation and


planning (reinforcement learning applications!)
- Training generative models can also enable inference of latent
representations that can be useful as general features
FIgures from L-R are copyright: (1) Alec Radford et al. 2016; (2) David Berthelot et al. 2017; Phillip Isola et al. 2017. Reproduced with authors permission.

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 18 May 18, 2017
Taxonomy of Generative Models Direct
GAN
Generative models

Explicit density Implicit density

Markov Chain
Tractable density Approximate density
GSN
Fully Visible Belief Nets
- NADE
- MADE Variational Markov Chain
- PixelRNN/CNN
Variational Autoencoder Boltzmann Machine
Change of variables models
(nonlinear ICA)
Figure copyright and adapted from Ian Goodfellow, Tutorial on Generative Adversarial Networks, 2017.

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 19 May 18, 2017
Taxonomy of Generative Models Direct
Today: discuss 3 most GAN
popular types of generative Generative models
models today

Explicit density Implicit density

Markov Chain
Tractable density Approximate density
GSN
Fully Visible Belief Nets
- NADE
- MADE Variational Markov Chain
- PixelRNN/CNN
Variational Autoencoder Boltzmann Machine
Change of variables models
(nonlinear ICA)
Figure copyright and adapted from Ian Goodfellow, Tutorial on Generative Adversarial Networks, 2017.

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 20 May 18, 2017
PixelRNN and PixelCNN

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 21 May 18, 2017
Fully visible belief network
Explicit density model
Use chain rule to decompose likelihood of an image x into product of 1-d
distributions:

Likelihood of Probability of i’th pixel value


image x given all previous pixels

Then maximize likelihood of training data

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 22 May 18, 2017
Fully visible belief network
Explicit density model
Use chain rule to decompose likelihood of an image x into product of 1-d
distributions:

Likelihood of Probability of i’th pixel value


image x given all previous pixels
Complex distribution over pixel
values => Express using a neural
Then maximize likelihood of training data network!

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 23 May 18, 2017
Fully visible belief network
Explicit density model
Use chain rule to decompose likelihood of an image x into product of 1-d
distributions:

Will need to define


ordering of “previous
Likelihood of Probability of i’th pixel value pixels”
image x given all previous pixels
Complex distribution over pixel
values => Express using a neural
Then maximize likelihood of training data network!

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 24 May 18, 2017
PixelRNN [van der Oord et al. 2016]

Generate image pixels starting from corner

Dependency on previous pixels modeled


using an RNN (LSTM)

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 25 May 18, 2017
PixelRNN [van der Oord et al. 2016]

Generate image pixels starting from corner

Dependency on previous pixels modeled


using an RNN (LSTM)

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 26 May 18, 2017
PixelRNN [van der Oord et al. 2016]

Generate image pixels starting from corner

Dependency on previous pixels modeled


using an RNN (LSTM)

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 27 May 18, 2017
PixelRNN [van der Oord et al. 2016]

Generate image pixels starting from corner

Dependency on previous pixels modeled


using an RNN (LSTM)

Drawback: sequential generation is slow!

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 28 May 18, 2017
PixelCNN [van der Oord et al. 2016]

Still generate image pixels starting from


corner

Dependency on previous pixels now


modeled using a CNN over context region

Figure copyright van der Oord et al., 2016. Reproduced with permission.

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 29 May 18, 2017
PixelCNN [van der Oord et al. 2016]
Softmax loss at each pixel

Still generate image pixels starting from


corner

Dependency on previous pixels now


modeled using a CNN over context region

Training: maximize likelihood of training


images

Figure copyright van der Oord et al., 2016. Reproduced with permission.

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 30 May 18, 2017
PixelCNN [van der Oord et al. 2016]

Still generate image pixels starting from


corner

Dependency on previous pixels now


modeled using a CNN over context region

Training is faster than PixelRNN


(can parallelize convolutions since context region
values known from training images)

Generation must still proceed sequentially


=> still slow
Figure copyright van der Oord et al., 2016. Reproduced with permission.

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 31 May 18, 2017
Generation Samples

32x32 CIFAR-10 32x32 ImageNet


Figures copyright Aaron van der Oord et al., 2016. Reproduced with permission.

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 32 May 18, 2017
PixelRNN and PixelCNN
Pros: Improving PixelCNN performance
- Can explicitly compute likelihood - Gated convolutional layers
p(x) - Short-cut connections
- Explicit likelihood of training - Discretized logistic loss
data gives good evaluation - Multi-scale
metric - Training tricks
- Good samples - Etc…

Con: See
- Sequential generation => slow - Van der Oord et al. NIPS 2016
- Salimans et al. 2017
(PixelCNN++)

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 33 May 18, 2017
Variational
Autoencoders (VAE)

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 34 May 18, 2017
So far...
PixelCNNs define tractable density function, optimize likelihood of training data:

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 35 May 18, 2017
So far...
PixelCNNs define tractable density function, optimize likelihood of training data:

VAEs define intractable density function with latent z:

Cannot optimize directly, derive and optimize lower bound on likelihood instead

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 36 May 18, 2017
Some background first: Autoencoders
Unsupervised approach for learning a lower-dimensional feature representation
from unlabeled training data

Features

Encoder
Input data

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 37 May 18, 2017
Some background first: Autoencoders
Unsupervised approach for learning a lower-dimensional feature representation
from unlabeled training data

Originally: Linear +
nonlinearity (sigmoid)
Later: Deep, fully-connected
Later: ReLU CNN

Features

Encoder
Input data

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 38 May 18, 2017
Some background first: Autoencoders
Unsupervised approach for learning a lower-dimensional feature representation
from unlabeled training data

z usually smaller than x Originally: Linear +


(dimensionality reduction) nonlinearity (sigmoid)
Later: Deep, fully-connected
Q: Why dimensionality
Later: ReLU CNN
reduction?

Features

Encoder
Input data

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 39 May 18, 2017
Some background first: Autoencoders
Unsupervised approach for learning a lower-dimensional feature representation
from unlabeled training data

z usually smaller than x Originally: Linear +


(dimensionality reduction) nonlinearity (sigmoid)
Later: Deep, fully-connected
Q: Why dimensionality
Later: ReLU CNN
reduction?

A: Want features to
capture meaningful Features
factors of variation in
data Encoder
Input data

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 40 May 18, 2017
Some background first: Autoencoders
How to learn this feature representation?

Features

Encoder
Input data

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 41 May 18, 2017
Some background first: Autoencoders
How to learn this feature representation?
Train such that features can be used to reconstruct original data
“Autoencoding” - encoding itself

Reconstructed
input data
Decoder
Features

Encoder
Input data

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 42 May 18, 2017
Some background first: Autoencoders
How to learn this feature representation?
Train such that features can be used to reconstruct original data
“Autoencoding” - encoding itself
Originally: Linear +
nonlinearity (sigmoid)
Reconstructed Later: Deep, fully-connected
input data Later: ReLU CNN (upconv)
Decoder
Features

Encoder
Input data

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 43 May 18, 2017
Some background first: Autoencoders Reconstructed data

How to learn this feature representation?


Train such that features can be used to reconstruct original data
“Autoencoding” - encoding itself

Reconstructed Encoder: 4-layer conv


input data Decoder: 4-layer upconv
Decoder
Input data
Features

Encoder
Input data

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 44 May 18, 2017
Some background first: Autoencoders Reconstructed data

Train such that features


can be used to L2 Loss function:
reconstruct original data

Reconstructed Encoder: 4-layer conv


input data Decoder: 4-layer upconv
Decoder
Input data
Features

Encoder
Input data

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 45 May 18, 2017
Some background first: Autoencoders Reconstructed data

Train such that features Doesn’t use labels!


can be used to L2 Loss function:
reconstruct original data

Reconstructed Encoder: 4-layer conv


input data Decoder: 4-layer upconv
Decoder
Input data
Features

Encoder
Input data

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 46 May 18, 2017
Some background first: Autoencoders

Reconstructed
input data
Decoder
Features After training,
throw away decoder
Encoder
Input data

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 47 May 18, 2017
Some background first: Autoencoders
Loss function
(Softmax, etc) bird plane
dog deer truck

Predicted Label
Fine-tune Train for final task
Classifier (sometimes with
Encoder can be encoder
jointly with small data)
used to initialize a Features
supervised model classifier
Encoder
Input data

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 48 May 18, 2017
Some background first: Autoencoders
Autoencoders can reconstruct
data, and can learn features to
initialize a supervised model

Reconstructed Features capture factors of


input data variation in training data. Can we
Decoder generate new images from an
autoencoder?
Features

Encoder
Input data

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 49 May 18, 2017
Variational Autoencoders
Probabilistic spin on autoencoders - will let us sample from the model to generate data!

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 50 May 18, 2017
Variational Autoencoders
Probabilistic spin on autoencoders - will let us sample from the model to generate data!

Assume training data is generated from underlying unobserved (latent)


representation z

Sample from
true conditional

Sample from
true prior

Kingma and Welling, “Auto-Encoding Variational Bayes”, ICLR 2014

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 51 May 18, 2017
Variational Autoencoders
Probabilistic spin on autoencoders - will let us sample from the model to generate data!

Assume training data is generated from underlying unobserved (latent)


representation z
Intuition (remember from autoencoders!):
Sample from x is an image, z is latent factors used to
true conditional generate x: attributes, orientation, etc.

Sample from
true prior

Kingma and Welling, “Auto-Encoding Variational Bayes”, ICLR 2014

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 52 May 18, 2017
Variational Autoencoders
We want to estimate the true parameters
of this generative model.
Sample from
true conditional

Sample from
true prior

Kingma and Welling, “Auto-Encoding Variational Bayes”, ICLR 2014

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 53 May 18, 2017
Variational Autoencoders
We want to estimate the true parameters
of this generative model.
Sample from How should we represent this model?
true conditional

Sample from
true prior

Kingma and Welling, “Auto-Encoding Variational Bayes”, ICLR 2014

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 54 May 18, 2017
Variational Autoencoders
We want to estimate the true parameters
of this generative model.
Sample from How should we represent this model?
true conditional
Choose prior p(z) to be simple, e.g.
Gaussian. Reasonable for latent attributes,
e.g. pose, how much smile.
Sample from
true prior

Kingma and Welling, “Auto-Encoding Variational Bayes”, ICLR 2014

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 55 May 18, 2017
Variational Autoencoders
We want to estimate the true parameters
of this generative model.
Sample from How should we represent this model?
true conditional
Choose prior p(z) to be simple, e.g.
Decoder Gaussian.
network
Sample from Conditional p(x|z) is complex (generates
true prior image) => represent with neural network

Kingma and Welling, “Auto-Encoding Variational Bayes”, ICLR 2014

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 56 May 18, 2017
Variational Autoencoders
We want to estimate the true parameters
of this generative model.
Sample from
How to train the model?
true conditional

Decoder
network
Sample from
true prior

Kingma and Welling, “Auto-Encoding Variational Bayes”, ICLR 2014

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 57 May 18, 2017
Variational Autoencoders
We want to estimate the true parameters
of this generative model.
Sample from
How to train the model?
true conditional
Remember strategy for training generative
Decoder models from FVBNs. Learn model parameters
network
to maximize likelihood of training data
Sample from
true prior

Kingma and Welling, “Auto-Encoding Variational Bayes”, ICLR 2014

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 58 May 18, 2017
Variational Autoencoders
We want to estimate the true parameters
of this generative model.
Sample from
How to train the model?
true conditional
Remember strategy for training generative
Decoder models from FVBNs. Learn model parameters
network
to maximize likelihood of training data
Sample from
true prior

Now with latent z

Kingma and Welling, “Auto-Encoding Variational Bayes”, ICLR 2014

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 59 May 18, 2017
Variational Autoencoders
We want to estimate the true parameters
of this generative model.
Sample from
How to train the model?
true conditional
Remember strategy for training generative
Decoder models from FVBNs. Learn model parameters
network
to maximize likelihood of training data
Sample from
true prior

Q: What is the problem with this?

Kingma and Welling, “Auto-Encoding Variational Bayes”, ICLR 2014

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 60 May 18, 2017
Variational Autoencoders
We want to estimate the true parameters
of this generative model.
Sample from
How to train the model?
true conditional
Remember strategy for training generative
Decoder models from FVBNs. Learn model parameters
network
to maximize likelihood of training data
Sample from
true prior

Q: What is the problem with this?


Intractable!
Kingma and Welling, “Auto-Encoding Variational Bayes”, ICLR 2014

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 61 May 18, 2017
Variational Autoencoders: Intractability
Data likelihood:

Kingma and Welling, “Auto-Encoding Variational Bayes”, ICLR 2014

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 62 May 18, 2017
Variational Autoencoders: Intractability

Data likelihood:

Simple Gaussian prior

Kingma and Welling, “Auto-Encoding Variational Bayes”, ICLR 2014

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 63 May 18, 2017
Variational Autoencoders: Intractability
✔ ✔
Data likelihood:

Decoder neural network

Kingma and Welling, “Auto-Encoding Variational Bayes”, ICLR 2014

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 64 May 18, 2017
Variational Autoencoders: Intractability
✔ ✔
Data likelihood:

Intractible to compute
p(x|z) for every z!

Kingma and Welling, “Auto-Encoding Variational Bayes”, ICLR 2014

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 65 May 18, 2017
Variational Autoencoders: Intractability
✔ ✔
Data likelihood:

Posterior density also intractable:

Kingma and Welling, “Auto-Encoding Variational Bayes”, ICLR 2014

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 66 May 18, 2017
Variational Autoencoders: Intractability
✔ ✔
Data likelihood:
✔ ✔
Posterior density also intractable:

Intractable data likelihood

Kingma and Welling, “Auto-Encoding Variational Bayes”, ICLR 2014

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 67 May 18, 2017
Variational Autoencoders: Intractability
✔ ✔
Data likelihood:
✔ ✔
Posterior density also intractable:

Solution: In addition to decoder network modeling pθ(x|z), define additional


encoder network qɸ(z|x) that approximates pθ(z|x)

Will see that this allows us to derive a lower bound on the data likelihood that is
tractable, which we can optimize

Kingma and Welling, “Auto-Encoding Variational Bayes”, ICLR 2014

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 68 May 18, 2017
Variational Autoencoders
Since we’re modeling probabilistic generation of data, encoder and decoder networks are probabilistic

Mean and (diagonal) covariance of z | x Mean and (diagonal) covariance of x | z

Encoder network Decoder network

(parameters ɸ) (parameters θ)

Kingma and Welling, “Auto-Encoding Variational Bayes”, ICLR 2014

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 69 May 18, 2017
Variational Autoencoders
Since we’re modeling probabilistic generation of data, encoder and decoder networks are probabilistic

Sample z from Sample x|z from

Encoder network Decoder network

(parameters ɸ) (parameters θ)

Kingma and Welling, “Auto-Encoding Variational Bayes”, ICLR 2014

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 70 May 18, 2017
Variational Autoencoders
Since we’re modeling probabilistic generation of data, encoder and decoder networks are probabilistic

Sample z from Sample x|z from

Encoder network Decoder network

(parameters ɸ) (parameters θ)

Encoder and decoder networks also called


“recognition”/“inference” and “generation” networks Kingma and Welling, “Auto-Encoding Variational Bayes”, ICLR 2014

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 71 May 18, 2017
Variational Autoencoders
Now equipped with our encoder and decoder networks, let’s work out the (log) data likelihood:

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 72 May 18, 2017
Variational Autoencoders
Now equipped with our encoder and decoder networks, let’s work out the (log) data likelihood:

Taking expectation wrt. z


(using encoder network) will
come in handy later

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 73 May 18, 2017
Variational Autoencoders
Now equipped with our encoder and decoder networks, let’s work out the (log) data likelihood:

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 74 May 18, 2017
Variational Autoencoders
Now equipped with our encoder and decoder networks, let’s work out the (log) data likelihood:

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 75 May 18, 2017
Variational Autoencoders
Now equipped with our encoder and decoder networks, let’s work out the (log) data likelihood:

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 76 May 18, 2017
Variational Autoencoders
Now equipped with our encoder and decoder networks, let’s work out the (log) data likelihood:

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 77 May 18, 2017
Variational Autoencoders
Now equipped with our encoder and decoder networks, let’s work out the (log) data likelihood:

The expectation wrt. z (using


encoder network) let us write
nice KL terms

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 78 May 18, 2017
Variational Autoencoders
Now equipped with our encoder and decoder networks, let’s work out the (log) data likelihood:

Decoder network gives pθ(x|z), can This KL term (between pθ(z|x) intractable (saw
compute estimate of this term through Gaussians for encoder and z earlier), can’t compute this KL
sampling. (Sampling differentiable prior) has nice closed-form term :( But we know KL
through reparam. trick, see paper.) solution! divergence always >= 0.

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 79 May 18, 2017
Variational Autoencoders
Now equipped with our encoder and decoder networks, let’s work out the (log) data likelihood:

Tractable lower bound which we can take


gradient of and optimize! (pθ(x|z) differentiable,
KL term differentiable)

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 80 May 18, 2017
Variational Autoencoders
Now equipped with our encoder and decoder networks, let’s work out the (log) data likelihood:

Variational lower bound (“ELBO”) Training: Maximize lower bound


Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 81 May 18, 2017
Variational Autoencoders
Now equipped with our encoder and decoder networks, let’s work out the (log) data likelihood:

Make approximate
Reconstruct posterior distribution
the input data close to prior

Variational lower bound (“ELBO”) Training: Maximize lower bound


Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 82 May 18, 2017
Variational Autoencoders
Putting it all together: maximizing the
likelihood lower bound

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 83 May 18, 2017
Variational Autoencoders
Putting it all together: maximizing the
likelihood lower bound

Let’s look at computing the bound


(forward pass) for a given minibatch of
input data

Input Data

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 84 May 18, 2017
Variational Autoencoders
Putting it all together: maximizing the
likelihood lower bound

Encoder network

Input Data

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 85 May 18, 2017
Variational Autoencoders
Putting it all together: maximizing the
likelihood lower bound

Make approximate
posterior distribution
close to prior
Encoder network

Input Data

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 86 May 18, 2017
Variational Autoencoders
Putting it all together: maximizing the
likelihood lower bound

Sample z from
Make approximate
posterior distribution
close to prior
Encoder network

Input Data

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 87 May 18, 2017
Variational Autoencoders
Putting it all together: maximizing the
likelihood lower bound

Decoder network

Sample z from
Make approximate
posterior distribution
close to prior
Encoder network

Input Data

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 88 May 18, 2017
Variational Autoencoders
Maximize
Putting it all together: maximizing the likelihood of Sample x|z from
likelihood lower bound original input
being
reconstructed

Decoder network

Sample z from
Make approximate
posterior distribution
close to prior
Encoder network

Input Data

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 89 May 18, 2017
Variational Autoencoders
Maximize
Putting it all together: maximizing the likelihood of Sample x|z from
likelihood lower bound original input
being
reconstructed

Decoder network

Sample z from
Make approximate
posterior distribution
close to prior
Encoder network
For every minibatch of input
data: compute this forward
pass, and then backprop! Input Data

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 90 May 18, 2017
Variational Autoencoders: Generating Data!
Use decoder network. Now sample z from prior!

Sample x|z from

Decoder network

Sample z from
Kingma and Welling, “Auto-Encoding Variational Bayes”, ICLR 2014

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 91 May 18, 2017
Variational Autoencoders: Generating Data!
Use decoder network. Now sample z from prior!

Sample x|z from

Decoder network

Sample z from
Kingma and Welling, “Auto-Encoding Variational Bayes”, ICLR 2014

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 92 May 18, 2017
Variational Autoencoders: Generating Data!
Use decoder network. Now sample z from prior! Data manifold for 2-d z

Sample x|z from


Vary z1

Decoder network

Sample z from
Kingma and Welling, “Auto-Encoding Variational Bayes”, ICLR 2014 Vary z2

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 93 May 18, 2017
Variational Autoencoders: Generating Data!
Diagonal prior on z
=> independent
Degree of smile
latent variables

Different
dimensions of z Vary z1
encode
interpretable factors
of variation

Head pose
Kingma and Welling, “Auto-Encoding Variational Bayes”, ICLR 2014 Vary z2

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 94 May 18, 2017
Variational Autoencoders: Generating Data!
Diagonal prior on z
=> independent
Degree of smile
latent variables

Different
dimensions of z Vary z1
encode
interpretable factors
of variation

Also good feature representation that


can be computed using qɸ(z|x)!
Head pose
Kingma and Welling, “Auto-Encoding Variational Bayes”, ICLR 2014 Vary z2

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 95 May 18, 2017
Variational Autoencoders: Generating Data!

Labeled Faces in the Wild


32x32 CIFAR-10
Figures copyright (L) Dirk Kingma et al. 2016; (R) Anders Larsen et al. 2017. Reproduced with permission.

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 96 May 18, 2017
Variational Autoencoders
Probabilistic spin to traditional autoencoders => allows generating data
Defines an intractable density => derive and optimize a (variational) lower bound
Pros:
- Principled approach to generative models
- Allows inference of q(z|x), can be useful feature representation for other tasks
Cons:
- Maximizes lower bound of likelihood: okay, but not as good evaluation as
PixelRNN/PixelCNN
- Samples blurrier and lower quality compared to state-of-the-art (GANs)
Active areas of research:
- More flexible approximations, e.g. richer approximate posterior instead of diagonal
Gaussian
- Incorporating structure in latent variables

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 97 May 18, 2017
Generative Adversarial
Networks (GAN)

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 98 May 18, 2017
So far...
PixelCNNs define tractable density function, optimize likelihood of training data:

VAEs define intractable density function with latent z:

Cannot optimize directly, derive and optimize lower bound on likelihood instead

Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - 99 May 18, 2017
So far...
PixelCNNs define tractable density function, optimize likelihood of training data:

VAEs define intractable density function with latent z:

Cannot optimize directly, derive and optimize lower bound on likelihood instead
What if we give up on explicitly modeling density, and just want ability to sample?

10
Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - May 18, 2017
0
So far...
PixelCNNs define tractable density function, optimize likelihood of training data:

VAEs define intractable density function with latent z:

Cannot optimize directly, derive and optimize lower bound on likelihood instead
What if we give up on explicitly modeling density, and just want ability to sample?

GANs: don’t work with any explicit density function!


Instead, take game-theoretic approach: learn to generate from training distribution
through 2-player game
10
Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - May 18, 2017
1
Ian Goodfellow et al., “Generative
Generative Adversarial Networks 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?

10
Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - May 18, 2017
2
Ian Goodfellow et al., “Generative
Generative Adversarial Networks 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 Output: Sample from


represent this complex training distribution
transformation?

A: A neural network! Generator


Network

Input: Random noise z

10
Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - May 18, 2017
3
Ian Goodfellow et al., “Generative
Training GANs: Two-player game Adversarial Nets”, NIPS 2014

Generator network: try to fool the discriminator by generating real-looking images


Discriminator network: try to distinguish between real and fake images

10
Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - May 18, 2017
4
Ian Goodfellow et al., “Generative
Training GANs: Two-player game Adversarial Nets”, NIPS 2014

Generator network: try to fool the discriminator by generating real-looking images


Discriminator network: try to distinguish between real and fake images

Real or Fake

Discriminator Network

Fake Images Real Images


(from generator) (from training set)

Generator Network

Random noise z
Fake and real images copyright Emily Denton et al. 2015. Reproduced with permission.

10
Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - May 18, 2017
5
Ian Goodfellow et al., “Generative
Training GANs: Two-player game Adversarial Nets”, NIPS 2014

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:

10
Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - May 18, 2017
6
Ian Goodfellow et al., “Generative
Training GANs: Two-player game Adversarial Nets”, NIPS 2014

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


Discriminator outputs likelihood in (0,1) of real image
Minimax objective function:

Discriminator output Discriminator output for


for real data x generated fake data G(z)

10
Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - May 18, 2017
7
Ian Goodfellow et al., “Generative
Training GANs: Two-player game Adversarial Nets”, NIPS 2014

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


Discriminator outputs likelihood in (0,1) of real image
Minimax objective function:

Discriminator output Discriminator output for


for real data x generated fake data G(z)

- Discriminator (θd) wants to maximize objective such that D(x) is close to 1 (real) and
D(G(z)) is close to 0 (fake)
- Generator (θg) wants to minimize objective such that D(G(z)) is close to 1
(discriminator is fooled into thinking generated G(z) is real)
10
Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - May 18, 2017
8
Ian Goodfellow et al., “Generative
Training GANs: Two-player game Adversarial Nets”, NIPS 2014

Minimax objective function:

Alternate between:
1. Gradient ascent on discriminator

2. Gradient descent on generator

10
Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - May 18, 2017
9
Ian Goodfellow et al., “Generative
Training GANs: Two-player game Adversarial Nets”, NIPS 2014

Minimax objective function:

Alternate between:
1. Gradient ascent on discriminator
Gradient signal
dominated by region
where sample is
2. Gradient descent on generator already good

When sample is likely


fake, want to learn
In practice, optimizing this generator objective from it to improve
does not work well! generator. But
gradient in this region
is relatively flat!
11
Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - May 18, 2017
0
Ian Goodfellow et al., “Generative
Training GANs: Two-player game Adversarial Nets”, NIPS 2014

Minimax objective function:

Alternate between:
1. Gradient ascent on discriminator

2. Instead: Gradient ascent on generator, different


objective

Instead of minimizing likelihood of discriminator being correct, now High gradient signal
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. Low gradient signal
11
Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - May 18, 2017
1
Ian Goodfellow et al., “Generative
Training GANs: Two-player game Adversarial Nets”, NIPS 2014

Minimax objective function:

Aside: Jointly training two


networks is challenging,
Alternate between: can be unstable. Choosing
1. Gradient ascent on discriminator objectives with better loss
landscapes helps training,
is an active area of
research.
2. Instead: Gradient ascent on generator, different
objective

Instead of minimizing likelihood of discriminator being correct, now High gradient signal
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. Low gradient signal
11
Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - May 18, 2017
2
Ian Goodfellow et al., “Generative
Training GANs: Two-player game Adversarial Nets”, NIPS 2014

Putting it together: GAN training algorithm

11
Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - May 18, 2017
3
Ian Goodfellow et al., “Generative
Training GANs: Two-player game Adversarial Nets”, NIPS 2014

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!

11
Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - May 18, 2017
4
Ian Goodfellow et al., “Generative
Training GANs: Two-player game Adversarial Nets”, NIPS 2014

Generator network: try to fool the discriminator by generating real-looking images


Discriminator network: try to distinguish between real and fake images

Real or Fake

Discriminator Network

Fake Images Real Images


(from generator) (from training set)

Generator Network
After training, use generator network to
Random noise z generate new images

Fake and real images copyright Emily Denton et al. 2015. Reproduced with permission.

11
Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - May 18, 2017
5
Ian Goodfellow et al., “Generative
Adversarial Nets”, NIPS 2014
Generative Adversarial Nets
Generated samples

Nearest neighbor from training set Figures copyright Ian Goodfellow et al., 2014. Reproduced with permission.

11
Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - May 18, 2017
6
Ian Goodfellow et al., “Generative
Adversarial Nets”, NIPS 2014
Generative Adversarial Nets
Generated samples (CIFAR-10)

Nearest neighbor from training set Figures copyright Ian Goodfellow et al., 2014. Reproduced with permission.

11
Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - May 18, 2017
7
Generative Adversarial Nets: Convolutional Architectures

Generator is an upsampling network with fractionally-strided convolutions


Discriminator is a convolutional network

Radford et al, “Unsupervised Representation Learning with Deep Convolutional Generative Adversarial Networks”, ICLR 2016
11
Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - May 18, 2017
8
Generative Adversarial Nets: Convolutional Architectures

Generator
Radford et al, “Unsupervised Representation Learning with Deep Convolutional Generative Adversarial Networks”, ICLR 2016
11
Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - May 18, 2017
9
Generative Adversarial Nets: Convolutional Architectures

Samples
from the
model look
amazing!

Radford et al,
ICLR 2016
12
Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - May 18, 2017
0
Generative Adversarial Nets: Convolutional Architectures

Interpolating
between
random
points in latent
space

Radford et al,
ICLR 2016
12
Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - May 18, 2017
1
Generative Adversarial Nets: Interpretable Vector Math
Radford et al, ICLR 2016
Smiling woman Neutral woman Neutral man

Samples
from the
model

12
Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - May 18, 2017
2
Generative Adversarial Nets: Interpretable Vector Math
Radford et al, ICLR 2016
Smiling woman Neutral woman Neutral man

Samples
from the
model

Average Z
vectors, do
arithmetic
12
Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - May 18, 2017
3
Generative Adversarial Nets: Interpretable Vector Math
Radford et al, ICLR 2016
Smiling woman Neutral woman Neutral man

Smiling Man
Samples
from the
model

Average Z
vectors, do
arithmetic
12
Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - May 18, 2017
4
Generative Adversarial Nets: Interpretable Vector Math
Glasses man No glasses man No glasses woman

Radford et al,
ICLR 2016

12
Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - May 18, 2017
5
Generative Adversarial Nets: Interpretable Vector Math
Glasses man No glasses man No glasses woman Radford et al,
ICLR 2016

Woman with glasses

12
Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - May 18, 2017
6
2017: Year of the GAN Text -> Image Synthesis

Better training and generation Source->Target domain transfer

Reed et al. 2017.


Many GAN applications

LSGAN. Mao et al. 2017.

Pix2pix. Isola 2017. Many examples at


CycleGAN. Zhu et al. 2017. https://phillipi.github.io/pix2pix/
BEGAN. Bertholet et al. 2017.
12
Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - May 18, 2017
7
“The GAN Zoo”

https://github.com/hindupuravinash/the-gan-zoo
12
Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - May 18, 2017
8
See also: https://github.com/soumith/ganhacks for tips

“The GAN Zoo” and tricks for trainings GANs

https://github.com/hindupuravinash/the-gan-zoo
12
Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - May 18, 2017
9
GANs
Don’t work with an explicit density function
Take game-theoretic approach: learn to generate from training distribution through 2-player
game

Pros:
- Beautiful, state-of-the-art samples!

Cons:
- Trickier / more unstable to train
- Can’t solve inference queries such as p(x), p(z|x)

Active areas of research:


- Better loss functions, more stable training (Wasserstein GAN, LSGAN, many others)
- Conditional GANs, GANs for all kinds of applications

13
Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - May 18, 2017
0
Recap
Generative Models

- PixelRNN and PixelCNN Explicit density model, optimizes exact likelihood, good
samples. But inefficient sequential generation.

- Variational Autoencoders (VAE) Optimize variational lower bound on likelihood. Useful


latent representation, inference queries. But current
sample quality not the best.
- Generative Adversarial Networks (GANs) Game-theoretic approach, best samples!
But can be tricky and unstable to train,
no inference queries.

13
Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - May 18, 2017
1
Recap
Generative Models

- PixelRNN and PixelCNN Explicit density model, optimizes exact likelihood, good
samples. But inefficient sequential generation.

- Variational Autoencoders (VAE) Optimize variational lower bound on likelihood. Useful


latent representation, inference queries. But current
sample quality not the best.
- Generative Adversarial Networks (GANs) Game-theoretic approach, best samples!
But can be tricky and unstable to train,
Also recent work in combinations of no inference queries.
these types of models! E.g. Adversarial
Autoencoders (Makhanzi 2015) and
PixelVAE (Gulrajani 2016)

13
Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - May 18, 2017
2
Recap
Generative Models

- PixelRNN and PixelCNN Explicit density model, optimizes exact likelihood, good
samples. But inefficient sequential generation.

- Variational Autoencoders (VAE) Optimize variational lower bound on likelihood. Useful


latent representation, inference queries. But current
sample quality not the best.
- Generative Adversarial Networks (GANs) Game-theoretic approach, best samples!
But can be tricky and unstable to train,
no inference queries.

Next time: Reinforcement Learning

13
Fei-Fei Li & Justin Johnson & Serena Yeung Lecture 13 - May 18, 2017
3

You might also like