Discrete Latent Representation For Image Generation
Fabianaugie Jametoni
Contents
2
Discrete Vs Continuous
Discrete Vs Continuous
4
Which one is bigger? the amount of number between 1 and ∞ or between 0 and 1?
Discrete Vs Continuous
5
Which one is bigger? the number between 1-Infinity or between 0-1?
Discrete Vs Continuous
6
So, case closed then. Continuous latent space are better than discrete latent space for generative model
Discrete Vs Continuous
7
So, case closed then. Continuous latent space are better than discrete latent space for generative model��Well….. Not Yet
Discrete Vs Continuous
8
Not Yet
Discrete Vs Continuous
9
So how does it work?
VQ-VAE And VQ-GAN
VQ-VAE And VQ-GAN
11
Introduction
VQ-VAE And VQ-GAN
12
Introduction
But what does exactly the lookup table, look up? What is the meaning of all this number?
VQ-VAE And VQ-GAN
13
Introduction
The codebook store the centroid of a data distribution, so in a way, discrete model still use continuous latent space for data representation, the different is that discrete model has a lot of small distribution representing some part of the image, unlike continuous model that only has one giant continuous representation to represent the data
C1
C2
C5
C4
C3
C
VQ-VAE And VQ-GAN
14
Introduction
happiness
contentment
pleasure
joy
satisfaction
C
VQ-VAE And VQ-GAN
15
VQ-VAE
VQ-VAE And VQ-GAN
16
VQ-VAE
because of the discrete codebook, the gradient will be lost, so how are we gonna train the model?
VQ-VAE And VQ-GAN
17
VQ-VAE
Instead, what VQ-VAE do is they copy the gradient from decoder and used it in the enoceder! skipping the codebook entirely
VQ-VAE And VQ-GAN
18
VQ-VAE
VQ-VAE And VQ-GAN
19
VQ-VAE Loss
Reconstruction Loss
This is just the normal autoencoder loss which is the MSE between the input and output
VQ-VAE And VQ-GAN
20
VQ-VAE Loss
Reconstruction Loss
This loss are used to move the centroid to the embedding
Codebook Loss
CA
CB
VQ-VAE And VQ-GAN
21
VQ-VAE Loss
Reconstruction Loss
This loss are used to move the centroid to the embedding
Codebook Loss
CA
CB
VQ-VAE And VQ-GAN
22
VQ-VAE Loss
Reconstruction Loss
This loss are used to move the centroid to the embedding
Codebook Loss
CA
CB
VQ-VAE And VQ-GAN
23
VQ-VAE Loss
Reconstruction Loss
This loss are used to move the centroid to the embedding
Codebook Loss
CA
CB
VQ-VAE And VQ-GAN
24
VQ-VAE Loss
Reconstruction Loss
Codebook Loss
CA
CB
Commitment Loss
You can think of this loss as the reverse of Codebook loss, this loss basically move the embedding to the centroid, this ensure that the embedding commit to 1 centroid and don't fluctuate between 2 or more centroid
VQ-VAE And VQ-GAN
25
VQ-VAE Loss
Reconstruction Loss
Codebook Loss
CA
CB
Commitment Loss
You can think of this loss as the reverse of Codebook loss, this loss basically move the embedding to the centroid, this ensure that the embedding commit to 1 centroid and don't fluctuate between 2 or more centroid
VQ-VAE And VQ-GAN
26
VQ-VAE Loss
Reconstruction Loss
Codebook Loss
CA
CB
Commitment Loss
You can think of this loss as the reverse of Codebook loss, this loss basically move the embedding to the centroid, this ensure that the embedding commit to 1 centroid and don't fluctuate between 2 or more centroid
VQ-VAE And VQ-GAN
27
VQ-VAE Loss
Reconstruction Loss
You can think of this loss as the reverse of Codebook loss, this loss basically move the embedding to the centroid, this ensure that the embedding commit to 1 centroid and don't fluctuate between 2 or more centroid
Codebook Loss
CA
CB
Commitment Loss
VQ-VAE And VQ-GAN
28
VQ-GAN
VQ-VAE And VQ-GAN
29
Perceptual Loss
Input Image
Reconstructed Image
Pre-Trained Conv Network (CLiP, ResNet, MobileNet, DiNO, Etc.)
Label Image Conv Embedding
Reconstruction Image Conv Embedding
MSE
VQ-VAE And VQ-GAN
30
Patch GAN
BERT
BERT
32
BERT
BERT
33
Masked Token Prediction
MaskedGIT
MaskedGIT
35
MaskedGIT
MaskedGIT
36
MaskedGIT
In theory, maskedGIT can generate an image in a single pass. in practice however, the model do required multiple iteration in order to generate an image, first we create scheduler consist of a vector of float consisted of a value in range of 0-1, the size of ow which are the amount of our iteration, then, the generation algorithm goes as follow:
MaskedGIT
37
MaskedGIT
MaskedGIT
38
Training Detail
In the original paper, during training the ratio of masked token are sampled randomly to simulate the various decoding scenario. in practice however, i found that, instead of sample the ratio randomly, the result are better if the sample ration are uniformly sampled across batch on every epoch, the training took 200 epoch using Adam optimizer and Cross-Entropy for our loss function
MaskedGIT
39
Speed Comparison
Because the nature of transformer, we can parallelize the prediction process of every mask which speed up the prediction process compared to other method
MaskedGIT
40
Zero-Shot Editing Capabilities
Another capabilities of this model in in it capabilities of doing zero-shot image editing by masking part of the image and predicting the masked part specifically
Q&A
Thank You