C 03 Variational Autoencoders Generative Adversarial Network
C 03 Variational Autoencoders Generative Adversarial Network
Architecture
Variational Autoencoders and Generative
Adversarial Network
Quick Recap
Encoder
• Autoencoders are unsupervised learning models
• They are used for dimensionality reduction, data
Code compression, and feature extraction
Output Layer
Input Layer
It reconstructs the image to be as close as possible to the original image, indicating that the
network has learned a meaningful representation.
Encoding Decoding
This layer is
what we want.
Challenges in Autoencoders
• Data generation: Traditional autoencoders were limited in generating new, unseen data.
• Robustness in learning: Autoencoders often learn oversimplified representations,
missing the data's true complexity.
• Handling variability: Autoencoders struggled with the inherent variability and
randomness in data, which is crucial for tasks like image generation or simulation.
Note
Standard autoencoders' limitations have led to the development of Variational
Autoencoders (VAEs). VAEs overcome these challenges and create a more versatile and
effective generative model.
Introduction to Variational Autoencoders
Latent
Input Layer Output Layer
Representation
x1 ^
x 1
x2 ^
x 2
x3 x^3
x4 ^
x 4
x5 ^
x 5
x6 ^
x 6
x7 ^
x 7
x8 x^8
Functions of VAE
• VAEs are designed to learn the underlying probability distributions of the input
data, not to compress it.
• It can generate new data samples that are like the training data, making them
powerful for generative tasks.
• It provides a more robust and generalizable way of representing data, capturing its
inherent variability and complexity.
VAE Architecture
VAE architecture contains the same components as that of the autoencoders, such as:
Encoder Decoder
µz|x
Latent Space Encoder
Latent space
qø(z | x) Z pθ(x | z) ^
x x Decoder
Reconstruction loss
Ʃz|x KL Divergence term
Standard Devaition
Encoder
KL Divergence term
Roles of VAE Components
Encoder
Latent space
• Is a compressed representation of input data in the form
of a probability distribution
Decoder
• Encodes essential features for data reconstruction
Reconstruction loss
KL Divergence term
Roles of VAE Components
Encoder
Latent space
• Reconstructs input data from its latent space representation
Reconstruction loss
KL Divergence term
Roles of VAE Components
Encoder
KL Divergence term
Roles of VAE Components
Encoder
KL Divergence term
Quick Check
Training a Variational Autoencoder (VAE) is a multi-step process that enables it to unlock its powerful
generative capabilities.
Encoding 2 3 Sampling
6
Training and backpropagation
Data Collection
Here’re the steps for training process of a VAE, which provides valuable insights into how a
language model captures and recreates complex data patterns:
Duration: 20 minutes
Problem Statement:
The task involves implementing a Variational Autoencoder (VAE) using TensorFlow to generate images.
This requires understanding the intricacies of VAEs and applying this knowledge to a practical dataset.
The challenge is accentuated with the use of the MNIST dataset, which comprises digit images.
Objective:
The goal is to successfully employ a VAE with TensorFlow for image generation. The focus is on the
MNIST dataset, known for its 60,000 training examples and 10,000 testing examples of handwritten
digits. Each digit are size-normalized and centered in 28x28 pixel images. The digits will be transformed
into a 1-dimensional NumPy array consisting of 784 features (28*28). The primary aim is to use the VAE
to create new images that resemble those in the MNIST dataset.
Note
Please download the solution document from the Reference Material Section and
follow the Jupyter Notebook for step-by-step execution.
VAE Generative Applications
Image Generation
The greatest disadvantage of VAEs is that they tend to produce blurry and unrealistic outputs.
Note
GANs are known for producing high-quality, sharp, and realistic outputs,
particularly in image generation.
Generative Adversarial Network (GAN)
Introduction to GANs
Generative Adversarial Networks (GANs) are architectures in deep learning that use structures
like convolutional neural networks for generative modeling.
Source: https://arxiv.org/abs/1906.00446?ref=assemblyai.com
Introduction to GANs
GANs use two neural networks: a generator and a discriminator. These networks engage in an
adversarial relationship.
This adversarial dynamic forms a zero-sum game, where one network's progress is at the
expense of the other.
GAN Architecture
Each component has its own functionality in the workings of a Generative Adversarial Network (GAN).
The discriminator
The sample images are
The generator receives functions as a binary
generated, and the real
input and creates sample classifier, providing
samples are passed
images. probabilities ranging
to the discriminator.
from 0 to 1.
GAN Architecture
A result closer to 0
A result closer to 1
indicates a higher
indicates the likelihood
likelihood of the sample
of the sample being real.
being fake.
Note
Both the generator and discriminator are implemented using CNNs
(Convolutional Neural Networks), particularly for image-related tasks.
Quick Check
The below example demonstrates the generation of human faces that do not belong to any
real individuals.
Source: https://user-images.githubusercontent.com/6625384/64915614-b82efd00-d730-11e9-92e4-f3a6de1a5575.png
Benefits of GAN
• GANs operate in an unsupervised learning framework and don't require labeled data during
training.
• GANs can be applied to image-to-image translation tasks, like converting satellite images to
maps, black-and-white photos to color, or day-to-night scene translation.
• GANs can be used for style transfer in images, allowing for the synthesis of images in the style
of a particular artist or a given set of images.
Demo: Generating Fake Images with Generative Adversarial
Networks (GANs)
Duration: 20 minutes
Problem Statement:
The task is to implement Generative Adversarial Networks (GANs) for synthetic image generation. It
involves mastering GAN principles and applying them to a specific dataset, focusing on the interplay
between the generator and discriminator networks.
Objective:
The aim is to develop a GAN, using TensorFlow, to create fake images. The project centers on training
the generator network to produce images that can convincingly pass as real to the discriminator. The
goal is to demonstrate GANs' effectiveness in producing diverse, realistic images.
Note
Please download the solution document from the Reference Material Section and
follow the Jupyter Notebook for step-by-step execution.
Industrial Use Case of GAN
Difficult to train
Get Locations Limited subset
This assignment is designed to enhance understanding and skills in advanced AI technologies through
engaging tasks. It focuses on developing practical solutions using AI in various creative scenarios. The
objective is to deepen knowledge in the application of AI for innovative and generative tasks,
emphasizing hands-on experience in utilizing AI for diverse creative outputs.
Key Takeaways