DL Unit 5 QP Solution

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 19

SRES’s

SHREE RAMCHANDRA COLLEGE OF ENGINEERING


Lonikand, Pune – 412216
Ref.№: SRCOE/ COMP.ENGG. DEPT /2023-24/ Date:

Unit V
Deep Generative Models
University Question Paper Solution: -
---------------------------------------------------------------------------------------------------------------------
Q 1) Explain Boltzmann-machine in details. 6 Marks (M/J 2023)
Boltzmann Machines is an unsupervised DL model in which every node is connected to every
other node. That is, unlike the ANNs, CNNs, RNNs and SOMs, the Boltzmann Machines
are undirected (or the connections are bidirectional). Boltzmann Machine is not a
deterministic DL model but a stochastic or generative DL model. It is rather a representation
of a certain system. There are two types of nodes in the Boltzmann Machine — Visible
nodes — those nodes which we can and do measure, and the Hidden nodes – those nodes
which we cannot or do not measure. Although the node types are different, the Boltzmann
machine considers them as the same and everything works as one single system. The training
data is fed into the Boltzmann Machine and the weights of the system are adjusted accordingly.
Boltzmann machines help us understand abnormalities by learning about the working of the
system in normal conditions.
Boltzmann Machine

Energy-Based Models:
Boltzmann Distribution is used in the sampling distribution of the Boltzmann Machine. The
Boltzmann distribution is governed by the equation –
Pi = e(-∈i/kT)/ ∑e(-∈j/kT)
Pi - probability of system being in state i
∈i - Energy of system in state i
T - Temperature of the system
k - Boltzmann constant
∑e(-∈j/kT) - Sum of values for all possible states of the system
Boltzmann Distribution describes different states of the system and thus Boltzmann machines
create different states of the machine using this distribution. From the above equation, as the
energy of system increases, the probability for the system to be in state ‘i’ decreases. Thus, the
system is the most stable in its lowest energy state (a gas is most stable when it spreads). Here,
in Boltzmann machines, the energy of the system is defined in terms of the weights of
synapses. Once the system is trained and the weights are set, the system always tries to find
the lowest energy state for itself by adjusting the weights.
Types of Boltzmann Machines:
• Restricted Boltzmann Machines (RBMs)
• Deep Belief Networks (DBNs)
• Deep Boltzmann Machines (DBMs)
Restricted Boltzmann Machines (RBMs):
In a full Boltzmann machine, each node is connected to every other node and hence the
connections grow exponentially. This is the reason we use RBMs. The restrictions in the node
connections in RBMs are as follows –
• Hidden nodes cannot be connected to one another.
• Visible nodes connected to one another.
Energy function example for Restricted Boltzmann Machine –
E(v, h) = -∑ aivi - ∑ bjhj - ∑∑ viwi,jhj
a, v - biases in the system - constants
vi, hj - visible node, hidden node
P(v, h) = Probability of being in a certain state
P(v, h) = e(-E(v, h))/Z
Z - sum if values for all possible states
Suppose that we are using our RBM for building a recommender system that works on six (6)
movies. RBM learns how to allocate the hidden nodes to certain features. By the process
of Contrastive Divergence, we make the RBM close to our set of movies that is our case or
scenario. RBM identifies which features are important by the training process. The training
data is either 0 or 1 or missing data based on whether a user liked that movie (1), disliked that
movie (0) or did not watch the movie (missing data). RBM automatically identifies important
features.
---------------------------------------------------------------------------------------------------------------
Q 2) Explain GAN (Generative Adversarial Network) architecture with an example.
6 Marks (M/J 2023)
: Generative Adversarial Networks (GANs) are a class of deep learning models introduced by
Ian Goodfellow and his colleagues in 2014. GANs consist of two neural networks, the generator
and the discriminator, which are trained simultaneously through a competitive process. The
generator aims to produce realistic data samples, while the discriminator tries to distinguish
between real and generated samples. This adversarial setup leads to the generator improving over
time to generate more realistic data, while the discriminator becomes better at distinguishing real
from fake data.
Here's a breakdown of the GAN architecture with an example:

1. Generator:
• The generator takes random noise or a random input and generates data samples
(e.g., images, sounds, text) from this input.
• It typically consists of a neural network that uses layers such as fully connected
layers, convolutional layers, and activation functions like ReLU or sigmoid.
• The goal of the generator is to produce data samples that are indistinguishable
from real data.
2. Discriminator:
• The discriminator is another neural network that takes input data samples and
predicts whether they are real (from the training data) or fake (generated by the
generator).
• Similar to the generator, the discriminator is composed of layers like fully
connected or convolutional layers followed by activation functions.
• The objective of the discriminator is to correctly classify real and fake samples
with high accuracy.
3. Training Process:
• During training, the generator and discriminator are trained in alternating steps.
• In the generator training step, the generator produces fake data samples from
random noise, and these samples are fed into the discriminator.
• The discriminator then evaluates the generated samples and provides feedback to
the generator. The generator's objective is to fool the discriminator into
classifying the fake samples as real.
• In the discriminator training step, both real and fake samples are presented to the
discriminator, and it is trained to correctly classify them.
• The generator and discriminator are trained iteratively in this adversarial manner,
with the generator getting better at generating realistic samples over time, and the
discriminator becoming more adept at distinguishing between real and fake
samples.
4. Example:
• Let's consider the task of generating images of handwritten digits (0-9) using a
GAN.
• The generator takes random noise as input and generates images of digits.
• The discriminator receives both real images of digits from a dataset (e.g., MNIST)
and fake images generated by the generator.
• Initially, the generator produces random noise, and the discriminator has a 50%
chance of correctly classifying real and fake images.
• As training progresses, the generator learns to generate more realistic digit
images, while the discriminator becomes better at distinguishing between real and
fake images.
• Eventually, the generator produces high-quality images that are indistinguishable
from real handwritten digits, and the discriminator achieves high accuracy in
discriminating between real and fake images.

In this way, GANs enable the generation of realistic data samples by learning the underlying data
distribution through a competitive process between the generator and the discriminator.

---------------------------------------------------------------------------------------------------------------------
Q3) Do GANs (Generative Adversarial Network) find real or fake images? If yes explain it
in detail . ------------------------------------------ 6 Marks (M/J 2023)
Ans: Generative Adversarial Networks (GANs) do not "find" images in the traditional sense.
Instead, GANs generate new images based on the patterns and features learned from a training
dataset. These generated images are synthesized by the generator network within the GAN
architecture.
Let's delve into the process of how GANs generate images:

1. Generator:
• The generator network in a GAN takes random noise as input and learns to
transform it into meaningful data samples, such as images.
• Initially, the generator produces random noise, but as it undergoes training, it
learns to generate increasingly realistic images.
• The generator typically consists of layers like fully connected or convolutional
layers, followed by activation functions. Through training, the weights of these
layers are adjusted to generate images that resemble the training data.
2. Discriminator:
• The discriminator network in a GAN is responsible for distinguishing between
real images from a dataset and fake images generated by the generator.
• It receives both real images from the dataset and fake images generated by the
generator as input.
• The discriminator is trained to classify these images as either real or fake with
high accuracy.
• As training progresses, the discriminator becomes better at distinguishing between
real and fake images.
3. Training Process:
• During training, the generator and discriminator networks are trained
simultaneously in a competitive manner.
• The generator aims to produce images that are realistic enough to fool the
discriminator into classifying them as real.
• On the other hand, the discriminator aims to correctly classify real images as real
and fake images as fake.
• Through this adversarial process, both networks improve iteratively. The
generator becomes better at generating realistic images, while the discriminator
becomes better at distinguishing real from fake images.
• The training continues until either a certain number of iterations are completed or
a convergence criterion is met, indicating that the generator is generating high-
quality images that are indistinguishable from real ones.
4. Generated Images:
• Once the GAN is trained, the generator can be used to generate new images by
providing random noise as input.
• These generated images are not "found" but rather created by the generator based
on the learned patterns and features from the training data.
• The quality of the generated images depends on the effectiveness of the GAN
training process and the complexity of the data distribution it has learned.

In summary, GANs do not find real or fake images; instead, they generate new images based on
the learned patterns from a training dataset. The generator within the GAN architecture
synthesizes images, while the discriminator distinguishes between real and fake images during
the training process.
--------------------------------------------------------------------------------------------------------------

Q 4) Differentiate generative and discriminative models in GAN (Generative Adversarial


Network). ------------------------------------------------ 6 Marks (M/J 2023)
Ans:-

Generative Vs Discriminative Model


Generative Model Discriminative Model

The basic goal of a generative model is to Data classification into distinct categories is
generate fresh data and to understand the the main objective of a discriminative model.
probability distribution of the input.
A large amount of input data is required for Labeled input data are necessary for
generative models in order to learn the discriminative models in order to learn where
probability distribution. one category ends and another begins.

The original data distribution and the fresh data An output label from discriminative models
created by generative models are similar. identifies the kind of input data.

Generative models are more challenging to Discriminative models are easier to create
construct than discriminative models since since they simply need to understand where
knowing the probability distribution of the data one category ends and another begins.
is necessary.

New data points that are produced by generative Due to their ability to recognize the
models can resemble the original data boundaries between many categories,
distribution. discriminative models perform better in
classification tasks.

The usage of generative models is common in In classification tasks like voice and picture
voice and picture recognition software. recognition, discriminative models are
frequently employed.

Unlabeled data can be analyzed by generative Labeled data are necessary for discriminative
models to discover the probability distribution of models to learn where one category ends and
the data. another begins.

As generative models learn the probability As discriminative models simply need to learn
distribution of the data, they are vulnerable to the border between several categories, they are
overfitting. less susceptible to overfitting.

---------------------------------------------------------------------------------------------------------------------
Q 5) What are applications of GAN (Generative Adversarial Network)? Explain any four
in details. ------------------------- 6 Marks (M/J 2023)
Ans:- Generative Adversarial Networks (GANs) have found numerous applications across
various domains due to their ability to generate realistic data samples. Here are four applications
of GANs explained in detail:

1. Image Generation and Editing:


• One of the most well-known applications of GANs is in generating and editing
images.
• GANs can generate high-resolution images of objects, scenes, faces, and more,
which can be useful in tasks like data augmentation for training deep learning
models.
• Conditional GANs allow for specific image generation, such as generating images
of a particular class or style.
• StyleGAN, a variant of GANs, has been particularly successful in generating
highly realistic images, leading to applications in creating photorealistic artwork,
generating synthetic data for computer vision tasks, and even creating deepfakes.
2. Data Augmentation:
• GANs can be used for data augmentation in various domains, including computer
vision and natural language processing.
• By generating synthetic data samples that closely resemble the real data, GANs
can expand the size and diversity of training datasets.
• This helps improve the generalization and robustness of machine learning models
trained on limited datasets.
• For example, in medical imaging, GANs can generate additional images of organs
or tissues to augment training data for better disease detection and diagnosis.
3. Image-to-Image Translation:
• GANs can perform image-to-image translation tasks, where an input image is
transformed into an output image with desired attributes.
• Examples include converting sketches to realistic images, colorizing grayscale
images, or changing day scenes to night scenes.
• Conditional GANs, such as Pix2Pix and CycleGAN, have been successful in
various image translation tasks by learning the mapping between input and output
domains.
• Applications include style transfer in photography, virtual try-on for fashion, and
image enhancement in computer graphics.
4. Drug Discovery and Molecular Design:
• GANs have been applied to drug discovery and molecular design, particularly in
generating novel chemical structures with desired properties.
• GANs can generate molecular structures with specific chemical properties, such
as drug-likeness or bioactivity, by learning the underlying distribution of chemical
compounds.
• This enables virtual screening of large chemical libraries to identify potential drug
candidates or optimize existing molecules for better efficacy and safety.
• GANs have also been used in de novo drug design, where new molecules are
generated with desired structural features for specific therapeutic targets.
-------------------------------------------------------------------------------------------------------------------

Q6) Write Short Note on Deep generative model and Deep Belief Networks. [6] M/J 23

Ans: Deep generative models are a class of artificial neural networks used in machine learning
and artificial intelligence. They are designed to generate new data samples that resemble a given
dataset. These models are particularly useful in tasks such as image generation, text generation,
and data synthesis.
One popular type of deep generative model is the Deep Belief Network (DBN). DBNs consist of
multiple layers of stochastic, latent variables, where each layer is trained using unsupervised
learning methods such as Restricted Boltzmann Machines (RBMs) or Contrastive Divergence
(CD). Once trained, DBNs can be used to generate new data samples by sampling from the
learned probability distributions.
DBNs have been successfully applied in various domains, including image recognition, natural
language processing, and recommendation systems. They are particularly well-suited for tasks
where generating realistic, high-dimensional data samples is challenging.
In summary, deep generative models, such as Deep Belief Networks, are powerful tools for
generating new data samples that closely resemble a given dataset, making them valuable in a
wide range of machine learning applications.

Deep generative models, including Deep Belief Networks (DBNs), have gained significant
attention due to their ability to learn complex data distributions and generate novel samples that
capture the characteristics of the training data. Here are some additional points to consider:

1. Learning Hierarchical Representations: One of the key advantages of deep generative


models is their capacity to learn hierarchical representations of data. Each layer in the
network learns increasingly abstract features of the data, capturing both low-level and
high-level patterns. This hierarchical representation enables the model to generate
samples with rich and diverse structures.
2. Unsupervised Learning: Deep generative models often utilize unsupervised learning
techniques during training, where the model learns from unlabeled data without explicit
supervision. Unsupervised learning is particularly valuable in scenarios where labeled
data is scarce or expensive to obtain. By exploiting the inherent structure of the data,
deep generative models can uncover meaningful patterns and generate realistic samples.
3. Variational Autoencoders (VAEs): Another popular type of deep generative model is the
Variational Autoencoder (VAE). VAEs are probabilistic models that learn to encode
input data into a low-dimensional latent space and decode it back to the original data
space. They are trained using a variational inference approach to approximate the
posterior distribution of the latent variables. VAEs offer a principled framework for
generative modeling and have been widely used in tasks such as image generation and
representation learning.
4. Applications: Deep generative models find applications in various domains, including
image generation, text generation, speech synthesis, drug discovery, and anomaly
detection. They are employed in creative applications such as generating artwork, music,
and literature. Additionally, they are utilized in practical applications like data
augmentation, where synthetic data is generated to augment training datasets and improve
the robustness of machine learning models.
5. Challenges: Despite their effectiveness, deep generative models face several challenges,
including scalability issues with high-dimensional data, training instability, mode
collapse (where the model fails to capture all modes of the data distribution), and
evaluation metrics for assessing the quality of generated samples. Addressing these
challenges is an active area of research in the field of generative modeling.
------------------------------------------------------------------------------------------------------------
Q7) Explain Deep generative model with example. ----------------- 6 Marks N/D 2023
Ans:- Deep generative models are a class of machine learning models that aim to
generate new data samples that are similar to those in the training set. These models
typically leverage deep learning architectures, such as deep neural networks, to capture
complex patterns and structures in the data.
One popular type of deep generative model is the Generative Adversarial Network
(GAN), proposed by Ian Goodfellow and his colleagues in 2014. In a GAN, two neural
networks are trained simultaneously: a generator and a discriminator.
The generator takes random noise as input and generates samples that resemble the
data from the training set. Initially, these generated samples may look like random
noise, but as the generator learns, it improves its ability to generate realistic samples.
The discriminator, on the other hand, acts as a binary classifier that distinguishes
between real samples from the training data and fake samples generated by the
generator. It is trained to assign high probabilities to real samples and low probabilities
to fake samples.
During training, the generator aims to generate samples that fool the discriminator into
classifying them as real, while the discriminator aims to correctly distinguish between
real and fake samples. This adversarial training process encourages both networks to
improve until a point where the generator generates realistic samples that are
indistinguishable from real ones by the discriminator.
As an example, consider generating images of handwritten digits using a GAN. The
generator network takes random noise as input and produces images that resemble
handwritten digits, such as digits from 0 to 9. The discriminator network is trained to
distinguish between real handwritten digit images from a dataset like MNIST and fake
digit images generated by the generator.
As training progresses, the generator gets better at creating realistic-looking digit
images, while the discriminator gets better at distinguishing between real and fake
images. Eventually, the generator becomes proficient at generating convincing
handwritten digit images that are difficult for the discriminator to differentiate from real
ones.

Deep generative models, like GANs, have found applications in various domains
beyond generating realistic images, including:

1. Image Generation and Manipulation: GANs can generate high-resolution images


of faces, animals, scenery, etc. They can also be used for tasks like image-to-
image translation, where an image in one domain (e.g., a horse) is translated into
another domain (e.g., a zebra) while preserving relevant details.
2. Text Generation: Deep generative models can generate natural language text,
such as articles, stories, poems, or even dialogue. They can be trained on large
corpora of text data to learn the underlying structure and distribution of language.
3. Drug Discovery: Deep generative models have been used to generate novel
molecular structures with desired properties for drug discovery. These models
can explore vast chemical spaces and propose candidate molecules that have
the potential to become new drugs.
4. Music Generation: Generative models can create new music compositions in
various genres. By learning patterns and structures from existing music data,
these models can generate melodies, harmonies, and rhythms that sound
realistic and original.
5. Anomaly Detection: Deep generative models can learn the distribution of normal
data and detect anomalies or outliers. By comparing new data samples with the
learned distribution, these models can identify unusual instances that deviate
significantly from the norm, which is useful in fraud detection, cybersecurity, and
quality control.
6. Super-Resolution Imaging: GANs can enhance the resolution of low-resolution
images by generating high-frequency details that are missing in the original
image. This is useful in applications like medical imaging, satellite imaging, and
enhancing the quality of surveillance footage.
--------------------------------------------------------------------------------------------------------------
Q8) How does GAN timing scale with batch scale. 6 Marks N/D 23
Ans:-The timing of training a Generative Adversarial Network (GAN) can be influenced by
several factors, including the batch size used during training. The batch size refers to the number
of samples (real or fake) processed in each iteration of training. Generally, increasing the batch
size can have both positive and negative effects on the training time of a GAN.

Here's how the timing of training a GAN may scale with batch size:

1. Positive Scaling:
• In many cases, increasing the batch size can lead to faster training times,
especially when using modern deep learning frameworks optimized for parallel
processing, such as TensorFlow or PyTorch.
• With larger batch sizes, more samples are processed simultaneously, allowing for
more efficient computation on parallel hardware such as GPUs or TPUs.
• Parallel processing enables faster matrix operations and gradient computations,
leading to shorter training times per iteration.
2. Negative Scaling:
• Despite the potential for faster training times, increasing the batch size can also
lead to challenges and limitations:
• Memory Constraints: Larger batch sizes require more memory to store
activations, gradients, and parameters during training. This can be
particularly problematic for models with limited memory resources, such
as GPUs.
• Communication Overhead: In distributed training setups with multiple
GPUs or across multiple machines, increasing the batch size can lead to
increased communication overhead between devices or nodes, which may
offset the benefits of parallel processing.
• Generalization Performance: Larger batch sizes may result in less noise
during training, potentially leading to overfitting or reduced generalization
performance, especially for complex models like GANs.
• Convergence Stability: GAN training is notoriously challenging and
sensitive to hyperparameters. Increasing the batch size may introduce
instability in training dynamics, making it harder to achieve convergence.
3. Optimal Batch Size:
• The optimal batch size for training a GAN depends on various factors, including
the model architecture, dataset size, hardware resources, and training objectives.
• It often requires empirical experimentation to find the batch size that balances
training efficiency, memory constraints, convergence stability, and generalization
performance.

In summary, while increasing the batch size in training a GAN can lead to faster training times
due to improved parallel processing efficiency, it also introduces challenges such as memory
constraints, communication overhead, and convergence stability. Finding the optimal batch size
involves balancing these factors to achieve efficient and effective training.
List the application of GAN network with description
Generative Adversarial Networks (GANs) have found applications in various domains due to
their ability to generate realistic and diverse data samples. Here are some notable applications of
GANs along with brief descriptions:

1. Image Generation and Manipulation:


• GANs can generate high-resolution, photorealistic images of faces, animals,
landscapes, and other objects.
• They can also be used for image-to-image translation tasks, such as style transfer,
colorization, and super-resolution.
2. Data Augmentation:
• GANs can generate synthetic data samples to augment training datasets for
machine learning models.
• Augmented datasets can improve model generalization and performance,
especially in tasks with limited training data.
3. Image Editing and Reconstruction:
• GANs enable interactive image editing by allowing users to manipulate specific
attributes of an image, such as age, gender, or expression.
• They can also be used for image inpainting, where missing or damaged parts of an
image are reconstructed.
4. Text-to-Image Synthesis:
• GANs can generate images from textual descriptions, allowing users to create
visual content from text prompts.
• This capability has applications in creative content generation, design, and
storytelling.
5. Video Synthesis and Prediction:
• GANs can generate realistic video sequences by extending their image generation
capabilities to the temporal domain.
• They can also be used for video prediction tasks, such as future frame prediction
and video completion.
6. Style Transfer and Art Generation:
• GANs can transfer the style of one image onto another, allowing for creative
transformations and artistic rendering.
• They can generate artwork, including paintings, sketches, and abstract
compositions, based on input images or styles.
7. Medical Image Analysis:
• GANs are used for generating synthetic medical images to augment limited
datasets for tasks such as image segmentation, classification, and disease
diagnosis.
• They can also generate realistic anatomical structures for surgical planning and
training simulations.
8. Drug Discovery and Molecular Design:
• GANs can generate molecular structures with desired properties, aiding in drug
discovery and optimization.
• They enable the generation of novel chemical compounds and the exploration of
chemical space for drug development.
9. Privacy Preservation and Anonymization:
• GANs can be used to generate synthetic data samples that preserve the statistical
properties of the original data while ensuring privacy and anonymity.
• They enable data sharing and analysis while protecting sensitive information.
-----------------------------------------------------------------------------------------------------------------
Q9) Explain different types of GAN. ……………………………6 Marks N/D 2023
Ans:- Generative Adversarial Networks (GANs) have evolved since their introduction in 2014,
leading to the development of various types and variants tailored for different tasks and
applications. Here are some different types of GANs along with brief explanations:

1. Vanilla GAN:
• The original formulation of GAN proposed by Ian Goodfellow and his colleagues
in 2014.
• Consists of a generator and a discriminator trained simultaneously in a minimax
game.
• The generator learns to generate realistic samples to fool the discriminator, while
the discriminator learns to distinguish between real and fake samples.
2. Deep Convolutional GAN (DCGAN):
• Utilizes convolutional neural networks (CNNs) in both the generator and
discriminator architectures.
• Introduced by Radford et al. in 2015 to stabilize training and generate high-
quality images.
• Employs architectural guidelines such as using strided convolutions, batch
normalization, and avoiding fully connected layers.
3. Conditional GAN (cGAN):
• Extends the vanilla GAN framework to condition the generation process on
additional information, such as class labels or auxiliary data.
• Introduced by Mirza and Osindero in 2014.
• The generator and discriminator receive conditional information as input to
generate or discriminate samples belonging to specific classes or categories.
4. Wasserstein GAN (WGAN):
• Introduces Wasserstein distance (also known as Earth Mover's Distance) as a new
objective function to improve training stability and mode collapse.
• Proposed by Arjovsky et al. in 2017.
• The discriminator is trained to be a critic that estimates the Wasserstein distance
between the distributions of real and generated samples.
5. Least Squares GAN (LSGAN):
• Replaces the binary cross-entropy loss used in the original GAN with least
squares loss to stabilize training and improve sample quality.
• Introduced by Mao et al. in 2017.
• Minimizes the squared difference between the discriminator's predictions and the
target labels for real and fake samples.
6. CycleGAN:
• A type of GAN introduced by Zhu et al. in 2017 for unpaired image-to-image
translation.
• Consists of two generators and two discriminators trained to learn mappings
between two domains without paired examples.
• Utilizes cycle consistency loss to enforce that the reconstructed images from one
domain to the other remain unchanged.
7. StyleGAN:
• A type of GAN introduced by Karras et al. in 2019 for high-quality image
synthesis.
• Utilizes a progressive growing technique to gradually increase the resolution of
generated images during training.
• Introduces a style-based generator architecture that disentangles the latent space
into style and content representations, enabling precise control over image
attributes.
8. BigGAN:
• A variant of GAN introduced by Brock et al. in 2018 for generating high-
resolution and diverse images.
• Utilizes large-scale architectures and class-conditional training to generate high-
fidelity images across multiple classes.
• Achieves state-of-the-art results in image generation tasks, such as ImageNet
classification.
---------------------------------------------------------------------------------------------------------------------

You might also like