generative adversarial networks - github pagesgenerative adversarial networks. abstracting a bit the...

68
Generative Adversarial Networks Prem Seetharaman, CS349 1

Upload: others

Post on 25-May-2020

24 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Generative Adversarial Networks - GitHub PagesGenerative adversarial networks. Abstracting a bit The goal is to be able to construct points similar to the real points. Generator. Abstracting

Generative Adversarial NetworksPrem Seetharaman, CS349

1

Page 2: Generative Adversarial Networks - GitHub PagesGenerative adversarial networks. Abstracting a bit The goal is to be able to construct points similar to the real points. Generator. Abstracting

Generative models

Generative models are unsupervised. Their only task is to generate samples that look like real samples.

Real samples of faces ->

Page 3: Generative Adversarial Networks - GitHub PagesGenerative adversarial networks. Abstracting a bit The goal is to be able to construct points similar to the real points. Generator. Abstracting

Generative models

Generative models are unsupervised. Their only task is to generate samples that look like real samples.

Real samples of faces -> Generated faces!

Page 4: Generative Adversarial Networks - GitHub PagesGenerative adversarial networks. Abstracting a bit The goal is to be able to construct points similar to the real points. Generator. Abstracting

Generative models

With generative models, we can leverage unlabeled training data.

Page 5: Generative Adversarial Networks - GitHub PagesGenerative adversarial networks. Abstracting a bit The goal is to be able to construct points similar to the real points. Generator. Abstracting

Generative models

Some tasks have many solutions.

Example: generating speech for the same text in different styles.

Page 6: Generative Adversarial Networks - GitHub PagesGenerative adversarial networks. Abstracting a bit The goal is to be able to construct points similar to the real points. Generator. Abstracting

Generative models

Example: Multiple translations for a given text.

Page 7: Generative Adversarial Networks - GitHub PagesGenerative adversarial networks. Abstracting a bit The goal is to be able to construct points similar to the real points. Generator. Abstracting

Generative models

Central question: how do we model our training data?

Page 8: Generative Adversarial Networks - GitHub PagesGenerative adversarial networks. Abstracting a bit The goal is to be able to construct points similar to the real points. Generator. Abstracting

Generative models

In these faces for example, there are several “latent” factors at play. What are they?

Page 9: Generative Adversarial Networks - GitHub PagesGenerative adversarial networks. Abstracting a bit The goal is to be able to construct points similar to the real points. Generator. Abstracting

Distributions

Recall that training example - an image, an audio clip, etc. - can be thought of as a point in space.

Page 10: Generative Adversarial Networks - GitHub PagesGenerative adversarial networks. Abstracting a bit The goal is to be able to construct points similar to the real points. Generator. Abstracting

Distributions

Recall that training example - an image, an audio clip, etc. - can be thought of as a point in space.

Page 11: Generative Adversarial Networks - GitHub PagesGenerative adversarial networks. Abstracting a bit The goal is to be able to construct points similar to the real points. Generator. Abstracting

Distributions

Let’s put all of our training data into this space.

Page 12: Generative Adversarial Networks - GitHub PagesGenerative adversarial networks. Abstracting a bit The goal is to be able to construct points similar to the real points. Generator. Abstracting

Matching distributions

Then, generating data means to sample from this space such that the sampled points are near real points.

Red: sampled points Blue: real points

Page 13: Generative Adversarial Networks - GitHub PagesGenerative adversarial networks. Abstracting a bit The goal is to be able to construct points similar to the real points. Generator. Abstracting

Matching distributions

Recall that one way we did that was by fitting a GMM to the space and sampling from it.

GMM w/ 1 component

Page 14: Generative Adversarial Networks - GitHub PagesGenerative adversarial networks. Abstracting a bit The goal is to be able to construct points similar to the real points. Generator. Abstracting

Matching distributions

As the number of components gets higher, the sampled points start to overlap with the real points.

GMM w/ 3 components

Page 15: Generative Adversarial Networks - GitHub PagesGenerative adversarial networks. Abstracting a bit The goal is to be able to construct points similar to the real points. Generator. Abstracting

15

GMM with 1 component

Page 16: Generative Adversarial Networks - GitHub PagesGenerative adversarial networks. Abstracting a bit The goal is to be able to construct points similar to the real points. Generator. Abstracting

16

GMM with 10 components

Page 17: Generative Adversarial Networks - GitHub PagesGenerative adversarial networks. Abstracting a bit The goal is to be able to construct points similar to the real points. Generator. Abstracting

17

GMM with 50 components

Page 18: Generative Adversarial Networks - GitHub PagesGenerative adversarial networks. Abstracting a bit The goal is to be able to construct points similar to the real points. Generator. Abstracting

Lots of ways to make this happen

Many other methods for generative modeling: 1. Variational autoencoders 2. Autoregressive models 3. Generative adversarial

networks

Page 19: Generative Adversarial Networks - GitHub PagesGenerative adversarial networks. Abstracting a bit The goal is to be able to construct points similar to the real points. Generator. Abstracting

Abstracting a bitThe goal is to be able to construct points similar to the real points.

Generator

Page 20: Generative Adversarial Networks - GitHub PagesGenerative adversarial networks. Abstracting a bit The goal is to be able to construct points similar to the real points. Generator. Abstracting

Abstracting a bit

This is a good generator.

Generator

Page 21: Generative Adversarial Networks - GitHub PagesGenerative adversarial networks. Abstracting a bit The goal is to be able to construct points similar to the real points. Generator. Abstracting

Abstracting a bit

This is a bad generator.

Generator

Page 22: Generative Adversarial Networks - GitHub PagesGenerative adversarial networks. Abstracting a bit The goal is to be able to construct points similar to the real points. Generator. Abstracting

Abstracting a bitGenerators can produce multiple points that should hopefully be diverse.

Generator

Page 23: Generative Adversarial Networks - GitHub PagesGenerative adversarial networks. Abstracting a bit The goal is to be able to construct points similar to the real points. Generator. Abstracting

Abstracting a bitA generator that can only produce one “type” of real sample is bad. Called mode collapse.

Generator

Page 24: Generative Adversarial Networks - GitHub PagesGenerative adversarial networks. Abstracting a bit The goal is to be able to construct points similar to the real points. Generator. Abstracting

Abstracting a bitA generator that covers all of your training data is good! It produces diverse samples.

Generator

Page 25: Generative Adversarial Networks - GitHub PagesGenerative adversarial networks. Abstracting a bit The goal is to be able to construct points similar to the real points. Generator. Abstracting

A loss function for generators?So we have some definition for what makes a generator “good” or “bad”. How do we turn this into a loss function?

Generator

Page 26: Generative Adversarial Networks - GitHub PagesGenerative adversarial networks. Abstracting a bit The goal is to be able to construct points similar to the real points. Generator. Abstracting

Enter the discriminatorThe discriminator tries to tell a generated sample apart from a real sample.

Discriminator

Page 27: Generative Adversarial Networks - GitHub PagesGenerative adversarial networks. Abstracting a bit The goal is to be able to construct points similar to the real points. Generator. Abstracting

Enter the discriminatorThe discriminator tries to tell whether a sample is real or fake.

Discriminator REAL

Page 28: Generative Adversarial Networks - GitHub PagesGenerative adversarial networks. Abstracting a bit The goal is to be able to construct points similar to the real points. Generator. Abstracting

Enter the discriminatorThe discriminator tries to tell whether a sample is real or fake.

Discriminator FAKE

Page 29: Generative Adversarial Networks - GitHub PagesGenerative adversarial networks. Abstracting a bit The goal is to be able to construct points similar to the real points. Generator. Abstracting

Enter the discriminatorThe discriminator tries to tell whether a sample is real or fake.

Discriminator REAL

Page 30: Generative Adversarial Networks - GitHub PagesGenerative adversarial networks. Abstracting a bit The goal is to be able to construct points similar to the real points. Generator. Abstracting

Enter the discriminatorThe discriminator tries to tell whether a sample is real or fake.

Discriminator FAKE

Page 31: Generative Adversarial Networks - GitHub PagesGenerative adversarial networks. Abstracting a bit The goal is to be able to construct points similar to the real points. Generator. Abstracting

The whole pictureGenerator attempts to create a data point.

DiscriminatorGenerator

Page 32: Generative Adversarial Networks - GitHub PagesGenerative adversarial networks. Abstracting a bit The goal is to be able to construct points similar to the real points. Generator. Abstracting

The whole pictureIf this generated point is NOT close to the real points in the space…

DiscriminatorGenerator

Page 33: Generative Adversarial Networks - GitHub PagesGenerative adversarial networks. Abstracting a bit The goal is to be able to construct points similar to the real points. Generator. Abstracting

The whole pictureThe discriminator will easily say that it’s a fake point.

DiscriminatorGenerator FAKE

Page 34: Generative Adversarial Networks - GitHub PagesGenerative adversarial networks. Abstracting a bit The goal is to be able to construct points similar to the real points. Generator. Abstracting

The whole pictureBut if the generated point IS close to a real point…

DiscriminatorGenerator

Page 35: Generative Adversarial Networks - GitHub PagesGenerative adversarial networks. Abstracting a bit The goal is to be able to construct points similar to the real points. Generator. Abstracting

The whole pictureThen the discriminator might be fooled!

DiscriminatorGenerator REAL

Page 36: Generative Adversarial Networks - GitHub PagesGenerative adversarial networks. Abstracting a bit The goal is to be able to construct points similar to the real points. Generator. Abstracting

Generator’s goalFool the discriminator into thinking the generated points are real.

DiscriminatorGenerator REAL

Page 37: Generative Adversarial Networks - GitHub PagesGenerative adversarial networks. Abstracting a bit The goal is to be able to construct points similar to the real points. Generator. Abstracting

Discriminator’s goalDon’t be fooled by the generator.

DiscriminatorGenerator FAKE

Page 38: Generative Adversarial Networks - GitHub PagesGenerative adversarial networks. Abstracting a bit The goal is to be able to construct points similar to the real points. Generator. Abstracting

Generator takes as input a latent codeThe output of the generator is conditioned on random noise.

DiscriminatorGenerator REAL

Late

nt c

ode

Page 39: Generative Adversarial Networks - GitHub PagesGenerative adversarial networks. Abstracting a bit The goal is to be able to construct points similar to the real points. Generator. Abstracting

Generator takes as input a latent codeThe generator interprets this random noise as a point on a manifold.

DiscriminatorGenerator REAL

Late

nt c

ode

Page 40: Generative Adversarial Networks - GitHub PagesGenerative adversarial networks. Abstracting a bit The goal is to be able to construct points similar to the real points. Generator. Abstracting

Generator takes as input a latent code…and maps points on the manifold to a point in the space of the data.

DiscriminatorGenerator REAL

Late

nt c

ode

Page 41: Generative Adversarial Networks - GitHub PagesGenerative adversarial networks. Abstracting a bit The goal is to be able to construct points similar to the real points. Generator. Abstracting

Key points

Generator

Latent code

To create good fake data, a generator must know what real data looks like.

The generator attempts to generate samples that are likely under the true distribution.

The distribution is learned implicitly via the discriminator.

Page 42: Generative Adversarial Networks - GitHub PagesGenerative adversarial networks. Abstracting a bit The goal is to be able to construct points similar to the real points. Generator. Abstracting

Key points

The discriminator learns how to tell real data from fake data.

Thus, a GAN is like learning your loss function, rather than keeping it fixed! Discriminator

REAL or FAKE

Page 43: Generative Adversarial Networks - GitHub PagesGenerative adversarial networks. Abstracting a bit The goal is to be able to construct points similar to the real points. Generator. Abstracting

This is a game with two players!Player 1: The Generator Player 2: The Discriminator

DiscriminatorGenerator REAL

Late

nt c

ode

Page 44: Generative Adversarial Networks - GitHub PagesGenerative adversarial networks. Abstracting a bit The goal is to be able to construct points similar to the real points. Generator. Abstracting

This is a game with two players!Player 1: The Generator Player 2: The Discriminator

DiscriminatorGenerator REAL

Late

nt c

ode

Generator is a deep network!

Discriminator is a deep network!

Page 45: Generative Adversarial Networks - GitHub PagesGenerative adversarial networks. Abstracting a bit The goal is to be able to construct points similar to the real points. Generator. Abstracting

This is a game with two players!Each player seeks to maximize its own success and minimize the success of the other -> a minimax game

DiscriminatorGenerator REAL

Late

nt c

ode

Generator is a deep network!

Discriminator is a deep network!

Page 46: Generative Adversarial Networks - GitHub PagesGenerative adversarial networks. Abstracting a bit The goal is to be able to construct points similar to the real points. Generator. Abstracting

This is a game with two players!The two players are at odds with one another and are trained in an alternating fashion.

DiscriminatorGenerator REAL

Late

nt c

ode

Generator is a deep network!

Discriminator is a deep network!

Page 47: Generative Adversarial Networks - GitHub PagesGenerative adversarial networks. Abstracting a bit The goal is to be able to construct points similar to the real points. Generator. Abstracting

Keep the generator fixed. Generate a bunch of fake points.

DiscriminatorGenerator REAL

Late

nt c

ode

At first, the generator has no idea how to create fake points. The data is not close to the real points.

Page 48: Generative Adversarial Networks - GitHub PagesGenerative adversarial networks. Abstracting a bit The goal is to be able to construct points similar to the real points. Generator. Abstracting

Take a bunch of real points…

DiscriminatorGenerator REAL

Late

nt c

ode

…and feed them to the discriminator. The discriminator should output that these are real points. Use this as a training signal and backprop to train the discriminator.

FAKE

REAL

FAKE

REAL

Page 49: Generative Adversarial Networks - GitHub PagesGenerative adversarial networks. Abstracting a bit The goal is to be able to construct points similar to the real points. Generator. Abstracting

Take a bunch of real points…

DiscriminatorGenerator REAL

Late

nt c

ode

…and feed them to the discriminator. The discriminator should output that these are real points. Use this as a training signal and backprop to train the discriminator.

FAKE

REAL

FAKE

REAL

Backprop“REAL/FAKE” loss to discriminator

Page 50: Generative Adversarial Networks - GitHub PagesGenerative adversarial networks. Abstracting a bit The goal is to be able to construct points similar to the real points. Generator. Abstracting

Take a bunch of fake points…

DiscriminatorGenerator FAKE

Late

nt c

ode

…and feed them to the discriminator. The discriminator should output that these are fake points.

REAL

FAKE

REAL

FAKE

Backprop“REAL/FAKE” loss to discriminator

Page 51: Generative Adversarial Networks - GitHub PagesGenerative adversarial networks. Abstracting a bit The goal is to be able to construct points similar to the real points. Generator. Abstracting

Now keep discriminator fixed. Generate fake points again…

DiscriminatorGenerator

Late

nt c

ode

This time we will update the generator instead. Note how different points may be generated this time - this is due to the randomness of the latent code.

Page 52: Generative Adversarial Networks - GitHub PagesGenerative adversarial networks. Abstracting a bit The goal is to be able to construct points similar to the real points. Generator. Abstracting

Take these fake points…

DiscriminatorGenerator

Late

nt c

ode

…and feed them to the discriminator. This time, we want the generator to fool the discriminator.

FAKE

FAKE

FAKE

FAKE

FAKE

Page 53: Generative Adversarial Networks - GitHub PagesGenerative adversarial networks. Abstracting a bit The goal is to be able to construct points similar to the real points. Generator. Abstracting

Take these fake points…

DiscriminatorGenerator

Late

nt c

ode

However the generator doesn’t know the true data distribution yet! So the discriminator easily catches that we are making forgeries.

FAKE

FAKE

FAKE

FAKE

FAKE

Page 54: Generative Adversarial Networks - GitHub PagesGenerative adversarial networks. Abstracting a bit The goal is to be able to construct points similar to the real points. Generator. Abstracting

Update the generator.

DiscriminatorGenerator

Late

nt c

ode

Update the generator by backpropping through the discriminator.

Backprop negation of “REAL/FAKE” loss to generator.

FAKE

FAKE

FAKE

FAKE

FAKE

Page 55: Generative Adversarial Networks - GitHub PagesGenerative adversarial networks. Abstracting a bit The goal is to be able to construct points similar to the real points. Generator. Abstracting

Alternate between generator updates and discriminator updates.

DiscriminatorGenerator

Late

nt c

ode

REAL

REAL

FAKE

REAL

FAKE

Backprop“REAL/FAKE” loss to discriminator

Train the discriminator to tell fake points from real points…

Page 56: Generative Adversarial Networks - GitHub PagesGenerative adversarial networks. Abstracting a bit The goal is to be able to construct points similar to the real points. Generator. Abstracting

Alternate between generator updates and discriminator updates.

DiscriminatorGenerator

Late

nt c

ode

Generate new fake points…

Page 57: Generative Adversarial Networks - GitHub PagesGenerative adversarial networks. Abstracting a bit The goal is to be able to construct points similar to the real points. Generator. Abstracting

Alternate between generator updates and discriminator updates.

DiscriminatorGenerator

Late

nt c

ode

FAKE

FAKE

REAL

REAL

REAL

Backprop negation of “REAL/FAKE” loss to generator.

Update the generator to fool the discriminator.

Page 58: Generative Adversarial Networks - GitHub PagesGenerative adversarial networks. Abstracting a bit The goal is to be able to construct points similar to the real points. Generator. Abstracting

Alternate between generator updates and discriminator updates.

DiscriminatorGenerator

Late

nt c

ode

As this process continues…

Page 59: Generative Adversarial Networks - GitHub PagesGenerative adversarial networks. Abstracting a bit The goal is to be able to construct points similar to the real points. Generator. Abstracting

Alternate between generator updates and discriminator updates.

DiscriminatorGenerator

Late

nt c

ode

…the generator will start to put its generated points near the real points…

Page 60: Generative Adversarial Networks - GitHub PagesGenerative adversarial networks. Abstracting a bit The goal is to be able to construct points similar to the real points. Generator. Abstracting

Alternate between generator updates and discriminator updates.

DiscriminatorGenerator

Late

nt c

ode

..leading to the discriminator to believe they are real points!

REAL

REAL

REAL

REAL

REAL

Page 61: Generative Adversarial Networks - GitHub PagesGenerative adversarial networks. Abstracting a bit The goal is to be able to construct points similar to the real points. Generator. Abstracting

Time to add a bit of math

Credit to Bhiksha Raj at CMU for these images!

Page 62: Generative Adversarial Networks - GitHub PagesGenerative adversarial networks. Abstracting a bit The goal is to be able to construct points similar to the real points. Generator. Abstracting

Time to add a bit of math

Credit to Bhiksha Raj at CMU for these images!

Page 63: Generative Adversarial Networks - GitHub PagesGenerative adversarial networks. Abstracting a bit The goal is to be able to construct points similar to the real points. Generator. Abstracting

Time to add a bit of math

Credit to Bhiksha Raj at CMU for these images!

Page 64: Generative Adversarial Networks - GitHub PagesGenerative adversarial networks. Abstracting a bit The goal is to be able to construct points similar to the real points. Generator. Abstracting

Time to add a bit of math

Credit to Bhiksha Raj at CMU for these images!

Intuition: how do you tell two coins apart?

Flip them and compare them to what you expect.

Page 65: Generative Adversarial Networks - GitHub PagesGenerative adversarial networks. Abstracting a bit The goal is to be able to construct points similar to the real points. Generator. Abstracting

Time to add a bit of math

Credit to Bhiksha Raj at CMU for these images!

Green: you want high likelihood that x is real (because it is).

Red: you want low likelihood that G(z) is real (because it isn’t).

Page 66: Generative Adversarial Networks - GitHub PagesGenerative adversarial networks. Abstracting a bit The goal is to be able to construct points similar to the real points. Generator. Abstracting

Time to add a bit of math

Credit to Bhiksha Raj at CMU for these images!

D(x) -> coin flip for D on x

D(G(z)) -> coin flip for D on G(x)

Page 67: Generative Adversarial Networks - GitHub PagesGenerative adversarial networks. Abstracting a bit The goal is to be able to construct points similar to the real points. Generator. Abstracting

Time to add a bit of math

Credit to Bhiksha Raj at CMU for these images!

Expect 1, try to get 1

Expect 0, try to get 0

Page 68: Generative Adversarial Networks - GitHub PagesGenerative adversarial networks. Abstracting a bit The goal is to be able to construct points similar to the real points. Generator. Abstracting

Time to add a bit of math

Credit to Bhiksha Raj at CMU for these images!