Week 9 Generative Adversarial Networks
Week 9 Generative Adversarial Networks
Encoding
Input
Output Label
Generative Learning
Generative learning is an Unsupervised Learning task:
● There is a loss function → an auxiliary task that we know the answer to
● There is no ground truth with respect to the actual task that we want to
accomplish.
● We are learning the structure & distribution of data, rather than labels for
data!
Generative Models
A generative model is used to generate new data, using some input encoding:
Unconditional Generative Models
● Only get random noise as input
● No control over what category they generate
Conditional Generative Models
● One-hot encoding of the target category + random noise, or
● An embedding generated by another model (e.g., from CNN)
● User have a high-level control over what the model will generate
Generative Models
There are different families of deep generative models:
● Autoregressive Models We already
covered these
● Variational AutoEncoders (VAEs)
We are covering
● Generative Adversarial Networks (GANs)
it today
● Flow-Based Generative Models
We won’t
● Diffusion Models cover them in
this course
Problem with Autoencoders
Vanilla autoencoders generate blurry images
with blurry backgrounds
To minimize the MSE loss, autoencoders predict
the average pixel
Can we use a better loss function?
Generative Adversarial Networks
Generative Adversarial Networks
class Discriminator(nn.Module):
def __init__(self):
super(Discriminator, self).__init__()
self.model = nn.Sequential(
nn.Linear(28*28, 300),
nn.LeakyReLU(0.2),
nn.Linear(300, 100),
nn.LeakyReLU(0.2),
nn.Linear(100, 1))
class Generator(nn.Module):
def __init__(self):
super(Generator, self).__init__()
self.model = nn.Sequential(
nn.Linear(100, 300),
nn.LeakyReLU(0.2),
nn.Linear(300, 28*28),
nn.Sigmoid())
https://arxiv.org/pdf/1812.04948.pdf
Grayscale to Color
Grayscale to Color
Convert to Conditional
grayscale Generator
D Real/Fake
Discriminator
Conditional Generation
How could we have a GAN trained on MNIST output only specific digits?
Noise
C C
Style Transfer
Cycle GAN: Cycle loss is reconstruction loss between input to cyclegan and
output of cyclegan to ensure consistency
Style Transfer
Adversarial Attacks
Adversarial Examples
Adversarial Attacks
Goal: Choose a small perturbation ε on an image x so that a neural network f
misclassifies x + ε.
Approach: Use the same optimization process to choose ε to minimize the
probability that
f (x + ε) = correct class
We are treating ε as the parameters.
Targeted vs. Non-Targeted Attack
Non-targeted attack
● Minimize the probability that
f (x + ε) = correct class
Targeted attack
● Maximize the probability that
f (x + ε) = target class
White-Box vs. Black-Box Attacks
White-box attacks
● Assumes that the model is known
● We need to know the architectures and weights of f to optimize ε
Black-box attacks
● Don’t know the architectures and weights of f to optimize ε
● Substitute model mimicking target model with known, differentiable function
● Adversarial attacks often transfer across models!
3D Objects
Printed Pictures
Adversarial T-Shirts
https://arxiv.org/pdf/1910.11099v3.pdf
Defence Against Adversarial Attack
It is a very active area of research, and we still don’t know how to handle them.
Failed Defenses:
● Adding noise at test time
● Weight decay
● Dropout
Questions?