Open the src/input_opt.py
file. The network ./data/weights.pkl
contains network weights pre-trained on MNIST. Turn the network optimization problem around, and find an input that makes a particular output neuron extremely happy. In other words maximize,
Use jax.value_and_grad
to find the gradients of the network input jnp.ones
network input of shape [1, 28, 28, 1]
and
iteratively optimize it.
Normalize by subtracting the mean and deviding by the standard
deviation at every step. Execute your script with python src/input_opt.py
Reuse your MNIST digit recognition code. Implement IG as discussed in the lecture. Recall the equation
F partial xi denotes the gradients with respect to the input color-channels i. x prime denotes a baseline black image. And x symbolizes an input we are interested in. Finally, m denotes the number of summation steps from the black baseline image to the interesting input.
Follow the TODOs in ./src/mnist_integrated.py
and then run scripts/integrated_gradients.slurm
.
In this exercise we will consider 128 by 128-pixel fake images from StyleGAN and pictures of real people from the Flickr-Faces-HQ dataset.
Flickr-Faces-HQ images depict real people, such as the person below:
Generative adversarial networks allow the generation of fake images at scale. Does the picture below seem real?
How can we identify the fake? Given that modern neural networks can generate hundreds of fake images per second can we create a classifier to automate the process?
- Move to the
data
folder in your terminal. Download ffhq_style_gan.zip on bender using the commandIfgdown https://drive.google.com/uc?id=1MOHKuEVqURfCKAN9dwp1o2tuR19OTQCF
gdown
is not installed, typepip install gdown
and then try again. - Type
export UNZIP_DISABLE_ZIPBOMB_DETECTION=TRUE
to make unzipping big archives possible. - Extract the image pairs here by executing
unzip ffhq_style_gan.zip
in the terminal.
The desired outcome is to have a folder called ffhq_style_gan
in the project data-folder.
The load_folder
function from the util
module loads both real and fake data.
Code to load the data is already present in the deepfake_interpretation.py
file.
Compute log-scaled frequency domain representations of samples from both sources via
Above
Use the numpy functions jnp.log
, jnp.abs
, jnp.fft.fft2
. By default, fft2
transforms the last two axes. The last axis contains the color channels in this case. We are looking to transform the rows and columns.
Plot mean spectra for real and fake images as well as their difference over the entire validation or test sets. For that complete the TODOs in src/deepfake_interpretation.py
and run the script scripts/train.slurm
.
Train a linear classifier consisting of a single nn.Dense
-layer on the log-scaled Fourier coefficients using Flax. Plot the result. What do you see?