Deepfake
Deepfake has had a lot of traction in the past few months. In this blog post, we explore more on the architecture of the deepfake technology and how deep learning is used to make this application possible.
### What is deepfake?
Deepfake is a deep learning based image recreation algorithm that allows users to superimpose facial images. It's been widely used to create fake celebrity pornogrphic videos. There was an entire subreddit dedicated to the maintainence and development of the "fakeapp" before its eventual demise.
### Autoencoder
An autoencoder is a deep neural network atchitecture that is used in unsupervised learning, it consists of three parts, an encoder, a decoder and a latent space. The goal of an autoencoder is to encode high dimensional data to a low dimensional subspace by means of feature learning. [See more](/2018/04/17/autoencoder/)
We will be using autoencoders to come up with low dimensional representation of face images, as well as generation of new face images.
### Structure
The autoencoder we will be using is as follows
{: .center}

So essentially, there is 1 encoder responsible for embedding the faces into the latent space and 2 decoders to reconstruct the respective faces. To make an inference, i.e input face A and output face B, one simply uses an image of face A, get a latent representation from the encoder and pass it throught the decoder of face B.
Here are some code implementing the above idea in keras.
{% gist 30998de9f8b9c65ffef36007bfdf9aee %}
### Preparing the training data
To train a deepfake autoencoder, one must first acquire enough training data. For that we use the python package [google-images-download](https://github.com/hardikvasa/google-images-download)
{% gist c3292a782d87cce26daaed659108bfb5%}
From the downloaded images, we need to extract the faces. Python's OpenCV has a built in face detection API we can utilize.
asdfasdfasf
#### References
https://hackernoon.com/exploring-deepfakes-20c9947c22d9
https://blog.keras.io/building-autoencoders-in-keras.html
https://github.com/CumminUp07/imengine/blob/master/get_google_images.py