Original article was published on Artificial Intelligence on Medium
For setting up our deepfake, I’ll be using Aliaksandr Siarohin’s Google Colab code.
First, make sure you copy his code to your Google Drive since we don’t want to alter his code:
For a faster compile time go to “Runtime -> Change runtime type -> Select GPU”
Before we get started, we need to download a few required files from the Drive link below. You just need to download one .jpeg image, one .mp4 video, a
vox-cpk.pth.tar file, and a
vox-adv-cpk.pth.tar file. But if you need to check with the images and videos they provided, download everything.
After downloading the files, create a folder named
first-order-motion-model in your Google Drive and upload the downloaded files.
To run with your own data…
- If you want your face to be added to a video, then take a selfie and change its size to
256 X 256pixels (you can simply use Paint to edit the size). This is the input size that the model accepts.
Upload all your data to the
first-order-motion-model folder on your Drive.
To run your face on the videos they’ve provided, change the following code to your file name. Then follow the rest of the steps as presented.
source_image = imageio.imread('/content/gdrive/My Drive/first-order-motion-model/*File Name.png*')
- If you want someone else’s face to be added to your video file, that file also needs to be on the size of
256 X 256pixels.
To convert your video into the above size, scroll down to the part of the code labeled “Run on your data”. Remove the boilerplate code provided and add the following code:
!ffmpeg -i /content/gdrive/My\ Drive/first-order-motion-model/*File Name.mp4* -s 256x256 -c:a copy result.mp4
This will create a converted video
result.mp4 file into the
first-order-motion-model folder and change the following code from “Load driving video and source image”
driving_video = imageio.mimread('/content/first-order-model/result.mp4')
And that’s it. Here is an example I created using Nicolas Cage’s face and the TV show Friends.
I hope this quick start guide to setting up your very own deepfake was useful. Have fun making some funny content (nothing dangerous!). Thank you, and stay safe!