Generative_Models
Generative_Models
An autoencoder
neural network is an
Unsupervised Machine lear
ning
algorithm that applies
backpropagation, setting the
target values to be equal to
the inputs.
Autoencoders consists of
three layers:
1, Encoder
2, Code
3, Decoder
AUTOENCODER COMPONENTS:
Autoencoders consists of 4 main parts:
1- Encoder: In which the model learns how to reduce the input
dimensions and compress the input data into an encoded
representation.
2- Bottleneck: which is the layer that contains the compressed
representation of the input data. This is the lowest possible
dimensions of the input data.
3- Decoder: In which the model learns how to reconstruct the data
from the encoded representation to be as close to the original input
as possible.
4- Reconstruction Loss: This is the method that measures measure
how well the decoder is performing and how close the output is to
• Here is an example of the input/output image from the MNIST
dataset to an autoencoder.
EXAMPLE
• If we input image X and the encoder compresses data, which
is also called dimension reductions, the encoder chooses the
best features (colour, size, shades, shape etc.) and stores
highly compressed data in a space called a bottleneck or
latent space, this is called encoding process.
• Similarly, the latent vector or bottleneck pushes data to the
decoder, and it produces output image X’.
• With Loss = L(X, X’), we train the model to minimize the
reconstruction loss. And this process gets automated, which
is known as Autoencoder.
• This model tries to provide data which is close to original
data.
• This is very useful in compression and denoise the data.
• Autoencoder helps us store a lot of high volume data and
also helps dimension reductions.
WHY AUTOENCODERS PREFERRED OVER
PCA
• An autoencoder can learn non-
linear transformations with a non-linear activation
function and multiple layers.
• It doesn’t have to learn dense layers. It can
use convolutional layers to learn which is better for
video, image and series data.
• It is more efficient to learn several layers with an
autoencoder rather than learn one huge transformation
with PCA.
• An autoencoder provides a representation of each layer
as the output.
• It can make use of pre-trained layers from another
model to apply transfer learning to enhance the
encoder/decoder.
PROPERTIES OF AUTOENCODERS:
• Image Colouring :
• Generative models learn the distribution of the training data and help in
generating new data points from the learned distribution by sampling those
distribution.
• Deep generative models (DGM) are neural networks with many hidden layers
trained to approximate complicated, high-dimensional probability
distributions using a large number of samples.
• When trained successfully, we can use the DGMs to estimate the likelihood of
each observation and to create new samples from the underlying distribution.
• Generative models are not classification models.
APPROACHES TO GENERATIVE MODELS
• It was first described in a paper in 2014 by Ian Goodfellow and a standardized and
much stable model theory was proposed by Alec Radford in 2016 which is known as
DCGAN (Deep Convolutional General Adversarial Networks).
•
GENERATIVE ADVERSARIAL
NETWORKS
• The two neural networks that make up a GAN are referred to as the
generator and the discriminator. The generator is a
convolutional neural network and the discriminator is a
deconvolutional neural network.
• Generative adversarial networks (GANs) are algorithmic
architectures that use two neural networks, pitting one against the
other (thus the “adversarial”) in order to generate new, synthetic
instances of data that can pass for real data.
• They are used widely in image generation, video generation and
voice generation.
THE WORKING CAN BE VISUALIZED
Generative: To learn a
generative model, which
describes how data is
generated in terms of a
probabilistic model.
Adversarial: The training
of a model is done in an
adversarial setting.
Networks: Use deep
neural networks as the
artificial intelligence (AI)
algorithms for training
purpose.
LOSS FUNCTIONS
EXAMPLE
• Generator:
• It is trained to generate new dataset for example in computer
vision it generate new images from existing real world
images.
• Discriminator:
• It compares those images with some real world examples and
classify real and fake images.
HOW DOES GANS WORK?
• In GANs, there is a generator and a discriminator.
• The Generator generates fake samples of data(be it an image, audio,
etc.) and tries to fool the Discriminator.
• The Discriminator, on the other hand, tries to distinguish between the
real and fake samples.
• The Generator and the Discriminator are both Neural Networks and they
both run in competition with each other in the training phase.
• The steps are repeated several times and in this, the Generator and
Discriminator get better and better in their respective jobs after each
repetition.
STEPS FOR TRAINING
• Define The Problem – define the problem and collect data.
• Choose Architecture Of GAN – Depending on your problem
choose how your GAN should look like.
• Train Discriminator On Real Data – Train the discriminator with
real data to predict them as real for n number of times.
• Generate Fake Inputs For Generator – Generate fake samples
from the generator
• Train Discriminator On Fake Data – Train the discriminator to
predict the generated data as fake.
• Train Generator With The Output Of Discriminator – After
getting the discriminator predictions, train the generator to fool
TRAINING A GAN HAS TWO PARTS:
• GANs take a long time to train. On a single GPU a GAN might take hours,
and on a single CPU more than a day.
• Vanishing gradient:
• Research has suggested that if your discriminator is too good, then
generator training can fail due to vanishing gradients. In effect, an optimal
discriminator doesn't provide enough information for the generator to
make progress.
• If the discriminator is too weak and the generator produces non realistic
images that fool it too easily.
SOLUTION
• A GAN can have two loss functions: one for generator training and
one for discriminator training
• GANs try to replicate a probability distribution.
• They should therefore use loss functions that reflect the distance
between the distribution of the data generated by the GAN and the
distribution of the real data.
• minimax loss:
• Wasserstein loss:
CROSS ENTROPY LOSS
MINIMAX LOSS
• The original GAN paper notes that the above minimax loss
function can cause the GAN to get stuck in the early stages of
GAN training when the discriminator's job is very easy.
• The paper therefore suggests modifying the generator loss so
that the generator tries to maximize log D(G(z))
WASSERSTEIN LOSS