You are on page 1of 53

GAN

Generative Adversarial Networks

By: BENSLIMANE Bilal - CHOUKRI Yassine - ANNASSI Othmane - ARRAD Karim Pr.Hiba CHOUGRAD
01 General Introduction

02 GAN Architecture

Table Of Content
03 Types Of GAN

04 Implementation
Introduction
INTRODUCTION
Generative modeling is an unsupervised learning
task in machine learning that involves
automatically discovering and learning the
regularities or patterns in input data in such a
way that the model can be used to generate or
output new examples that plausibly could have
been drawn from the original dataset.
Why GAN's
DNN LIMITS

DNNs rely on large sets of labeled


data to perform their functions
DNN LIMITS

DNNs rely on large sets of labeled


data to perform their functions

Quality of data
DNN LIMITS

DNNs rely on large sets of labeled


data to perform their functions

Quality of data

Data with legal and


ethical implications
Question answered !
Create and improve new content that looked realistic in a
recursive process.

Since then, GAN has sparked many new innovations in the


domain of artificial intelligence.
Common applications
Image Super-Resolution : The ability to generate high-resolution
versions of input images.
Creating Art : The ability to great new and artistic images, sketches, painting ...
Image-to-Image Translation : generate photorealistic
images given a semantic image or sketch as input.
Generate New Human Poses
correct images and reconstruct obscure parts
Deep fake
Image-to-Image Translation : generate photorealistic
images given a semantic image or sketch as input.
Generate New Human Poses
correct images and reconstruct obscure parts
Deep fake
GAN Architecture
Definition
GAN
A generative adversarial network (GAN) is a machine
learning (ML) model in which two neural networks
(Generator & Discriminator models)compete with
each other to become more accurate in their
predictions.
GANs are a clever way of training a generative model
by framing the problem as a supervised learning
problem with two sub-models: the generator model that
we train to generate new examples, and the
discriminator model that tries to classify examples as
either real (from the domain) or fake (generated).
GAN Architectures
Global Architecture
2 Sub-Models

GAN Generator GAN Discriminator


The generator learns to generate plausible The discriminator learns to Distinguish the
data. generator's fake data from real data.
The discriminator penalizes the generator for
*Plausible data : Reliable data producing implausible results.
GAN Architectures
General Concept
Training phase:
When training begins, the Generator(G) produces obviously
fake data, and int the other side the Discriminator(D) quickly
learns to tell that it's fake.

As training progresses, the Generator gets closer to


producing output that can fool the Discriminator.
GAN Architectures
General Concept
Training phase:
When training begins, the Generator(G) produces obviously Final Result
fake data, and int the other side the Discriminator(D) quickly
learns to tell that it's fake.

Finally, if Generator training goes well, the Discriminator


gets worse at telling the difference between real and fake.
As training progresses, the Generator gets closer to It starts to classify fake data as real, and its accuracy
producing output that can fool the Discriminator. decreases.
GAN Architectures
General Concept
Training phase:
When training begins, the Generator(G) produces obviously Final Result
fake data, and int the other side the Discriminator(D) quickly
learns to tell that it's fake.

Finally, if Generator training goes well, the Discriminator


gets worse at telling the difference between real and fake.
As training progresses, the Generator gets closer to It starts to classify fake data as real, and its accuracy
producing output that can fool the Discriminator. decreases.

Real

Ac
G D =

cy
+

cu
ra
Image

cu

ra
cy
Ac
GAN Architectures
General Concept
Generator
Generator training requires tighter integration between the generator and the discriminator than discriminator training
requires. The portion of the GAN that trains the generator includes:

Random input.
Generator network, that transforms the random input into a data instance.
Discriminator output.
Generator loss, which penalizes the generator for failing to fool the discriminator.
Discriminator
The discriminator is a binary classifier. It tries to distinguish real data from the data created by the generator.
The discriminator's training data comes from two sources:
Real data: instances(such as real pictures of people), That the discriminator uses as positive examples during
training.
Fake data: instances are created by the generator. The discriminator uses these instances as negative examples
during training.
Discriminator
During Discriminator Training:

The discriminator classifies both real data and fake data from
the generator.
The D loss function penalizes the discriminator for
misclassifying a real instance as fake or a fake instance as
real.
The discriminator updates its weights through
backpropagation from the discriminator loss through the
discriminator network.
GAN Training
G D
Generator is Frozen Training the descriminator
REAL VS FAKE DATA
GAN Training
G D
Generator is Frozen Training the descriminator
REAL VS FAKE DATA

Training the Generator Discriminator is Frozen


Generating the DATA to be classified
GAN Training
G D
Generator is Frozen Training the descriminator
REAL VS FAKE DATA

Training the Generator Discriminator is Frozen


Generating the DATA to be classified

If G won If D Lost If G Lost If D won


TESTING
Reajusting the D model Reajusting the G model
(Changing D Weights) (Changing G Weights)
GAN Training
G D
Generator is Frozen Training the descriminator
REAL VS FAKE DATA

Training the Generator Discriminator is Frozen


Generating the DATA to be classified

If G won If D Lost If G Lost If D won


TESTING
Reajusting the D model Reajusting the G model
(Changing D Weights) (Changing G Weights)
G won: G was able to make D classify the fake
data as real one D won: D was able to correctly classify the data
Example

Distorted faces
Types of GAN
Types of GAN
DCGAN
It is a Deep convolutional GAN. It is one of the most used, powerful, and successful types of GAN
architecture. It is implemented with help of Convolutional neural network in place of a Multi-layered
perceptron.
A DCGAN is a GAN that uses deep convolutional layers as part of its architecture. You can think of it as a
convolutional neural network (CNN) and a GAN combined.
Types of GAN
DCGAN

The algorithm of DCGAN, which can be considered as the application of GAN extended to the field of CNN.
It combines CNN in supervised learning with GAN in unsupervised learning.

The advantage of GAN is that it requires no specific cost function and can learn good feature representation,
but GAN is very unstable to train and often causes generators to produce meaningless output. Compared
with GAN, DCGAN made some changes to the structure of convolutional neural network to improve the
quality of samples and the speed of convergence.
Types of GAN
DCGAN
z, the input of G is a noise, which can be gaussian noise.
a fake image is generated– G(z).
G (z) and x are taken as inputs to discriminator D.
The output of the final discriminator D represents the probability
that the data is real, which ranges from 0 to 1.
For discriminator, batch normalization is generally not required
after the first layer convolution, and the combination mode of
‘‘conv2D +BN+ LeakyReLU’’ is always followed.
For the generator, the first layer is the full connection layer, then
the combined mode of ‘‘conv2D+BN+ReLU’’, and the last layer of
convolution is activated by tanh
Types of GAN
BigGAN

BigGAN is a type of generative adversarial network that was designed for scaling generation to high-
resolution, high-fidelity images. It includes a number of incremental changes and innovations. The baseline
and incremental changes are:
Using SAGAN as a baseline with spectral norm. for G and D.
Using a Hinge Loss GAN objective
Using class-conditional batch normalization to provide class information to G.
Using a projection discriminator for D to provide class information to D.
Types of GAN
BigGAN

Examples of 512x512 images generated by the proposed method


Types of GAN
DVD-GAN
Dual Video Discriminator GAN is a GAN for video generation built upon the BigGAN architecture. DVD-GAN
uses two discriminators: a Spatial Discriminator and a Temporal Discriminator.

model consists of a generator to predict future frames and dual discriminators, one of which is used to
discriminate frames (appearance), and the other of which is used to distinguish the motion between true and
false.
Types of GAN
DVD-GAN
Process of Implementation
using DCGAN
Steps to Implement DCGAN
1 - Importing Libraries

This open-source machine learning


library is based on Torch and
designed to provide greater flexibility
and increased speed for deep neural
network implementation.

We imported our dataset "CelebA"


from Kaggle.com
Steps to Implement DCGAN
2 - Getting the Dataset

Torchvision is a library for Computer


Vision,It has utilities for efficient
Image and Video transformations,
some commonly used pre-trained
models, and some datasets

Here we composes several images


together and we specify some
parameters of the images.

Then we split our data into training-


set and testing-set.
Steps to Implement DCGAN
3 - Data checking

Steps to Implement DCGAN

Visualisation du Training-set
Steps to Implement DCGAN
3 - Generator function

First we apply a 2D transposed
convolution operator over an input image
composed of several input planes.

Leaky Rectified Linear Unit, or Leaky


ReLU, is a type of activation function
based on a ReLU, but it has a small slope
for negative values instead of a flat slope.
Steps to Implement DCGAN
3 - Generator function

Why we use Leaky RELU ?
Leaky relu helps the Gradient flow easily through the neural
network architecture.The ReLU activation function only
takes the maximum value between input and zero. If we use
ReLU then it is a chance that the network can get stuck in a
state known as Dying State. If this happens then it produces
nothing other than zero for all outputs.

Why Batch Normalization?


It has the effect of stabilizing the training process by
standardizing activations from the prior layer to have zero
mean and unit variance. Batch Normalization has become a
staple while training deep convolutional Networks and GANs
are no different from it.
Steps to Implement DCGAN
4 - Discriminator function

Conv2d : Two-dimensional convolution is applied over


an input given by the user where the specific shape of
the input is given in the form of size, length, width,
channels, and hence the output must be in a
convoluted manner is called PyTorch Conv2d.
Steps to Implement DCGAN
5 - Training the model

Steps to Implement DCGAN


6 - Evaluation

We evaluate the Loss for both of


Discriminator and the Generator during the
Traning period
Steps to Implement DCGAN
7- Results
Steps to Implement DCGAN
7- Results

Steps to Implement DCGAN


7- Results

Steps to Implement DCGAN


7- Results

Steps to Implement DCGAN


7- Results

Thanks

You might also like