Creating Your Own Deepfakes Without Coding Experience
Tags: tutorial, beginners, ai
Published: 2020-08-14 17:49:34

*[If you've found this article useful, consider donating.](https://www.patreon.com/alanjc)*

*[This article was originally published at my blog.](https://blog.alanjc.com/articles/creating-your-own-deepfakes-without-coding-experience.html)*

## Table of Contents
- [Deepfake Video Examples](#deepfake-video-examples)
- [Background](#background)
- [Things you'll need](#things-youll-need)
- [Before starting](#before-starting)
  - [Sign into your Google account](#sign-into-your-google-account)
  - [Connecting to the Google Colab](#connecting-to-the-google-colab)
- [Creating your own deepfakes](#creating-your-own-deepfakes)
  - [(Step 1) Cloning the Repo](#step-1-cloning-the-repo)
  - [(Step 2) Change your directory](#step-2-change-your-directory)
  - [(Step 3) Mounting your Google drive folder on Colab](#step-3-mounting-your-google-drive-folder-on-colab)
  - [(Step 4) Downloading the checkpoint (".pth.tar") files](#step-4-downloading-the-checkpoint-pthtar-files)
  - [(Step 5) Create a folder called "first-order-model-motion" in your Google Drive](#step-5-create-a-folder-called-first-order-model-motion-in-your-google-drive)
  - [(Step 6) Loading your image and video](#step-6-loading-your-image-and-video)
  - [(Step 7) Creating the model and loading the checkpoints](#step-7-creating-the-model-and-loading-the-checkpoints)
  - [(Step 8) Creating the deepfake](#step-8-creating-the-deepfake)
  - [(Step 9) Saving your deepfake](#step-9-saving-your-deepfake)
- [Errors](#errors)
- [Using your own image](#using-your-own-image)
- [Using your own video](#using-your-own-video)
- [Video tutorials](#video-tutorials)

## Deepfake Video Examples

[The Mona Lisa and Elon Musk](https://www.youtube.com/watch?v=GkOA0X-A58Q)
[Kim Kardashian and Dr. K](https://www.youtube.com/watch?v=QmdbtEPlOVA)
[Woman and Edward Snowden](https://www.youtube.com/watch?v=wSlC39NYenY)

## Background

In case you don't know, deepfakes are faked media that mimic another person's likeness, [like so](https://www.youtube.com/watch?v=_OqMkZNHWPo). This process is achieved through something called ["deep learning,"](https://en.wikipedia.org/wiki/Deep_learning) hence the name *deepfake*.

Creating your own deepfakes has been possible for a while now but the problem was that it required a lot of data, computing power, and time.

But now, thanks to the researchers Aliaksandr Siarohin, Stéphane Lathuilière, Sergey Tulyakov, Elisa Ricci and Nicu Sebe, their paper ["First Order Motion Model for Image Animation,"](https://aliaksandrsiarohin.github.io/first-order-model-website/) and their [implementation](https://github.com/AliaksandrSiarohin/first-order-model), we are now able to create a deepfakes with a single image.

Better yet, not only can we create deepfakes with a single image, but they also don't take hours or days to make, now they take only mere seconds and at most a couple of minutes. In addition, no coding experience is required.

If you'd like to understand more of how this works, you can watch this [video  by Two Minute Papers](https://www.youtube.com/watch?v=mUfJOQKdtAk).

## Things you'll need
- A [Google account](https://accounts.google.com/signup?hl=en)
- An image of what you want to animate
  - We'll be using a picture of The Mona Lisa
- A video to extract the animation from
  - We'll be using a video of Leonardo DiCaprio's face
- Some free time

## Before starting

### Sign into your Google account

Once you go to the [Google colab](https://colab.research.google.com/github/AliaksandrSiarohin/first-order-model/blob/master/demo.ipynb?authuser=1#scrollTo=UCMFMJV7K-ag), you'll be greeted with a page that looks like the following:

![Google Colab](https://dev-to-uploads.s3.amazonaws.com/i/zqjtsg2nmpvw4my8pi3s.png)

You'll need to sign in to your Google account to interact with this document.

I'd suggest you create a new [Google account here](https://accounts.google.com/signup?hl=en).

### Connecting to the Google Colab

After you have signed in, you'll want to actually connect to the Colab.

To do so click on the connect button at the top right of the page.

![Connecting to the colab](https://dev-to-uploads.s3.amazonaws.com/i/c9dq8ug5v5rp24j2f1s5.png)

If you don't get any error messages, you can skip straight to (Step 3).

If you get the following message, that means that you won't be able to use Google's GPU which essentially means you can't follow the tutorial at this time because all the GPUs are being used.

![Can't connect to GPU](https://dev-to-uploads.s3.amazonaws.com/i/3e5twskjp1pryt1bpqzc.png)

To fix this, you can either (1) wait and come back later, (2) upgrade to [colab pro](https://colab.research.google.com/signup), (3) [run this repository](https://github.com/AliaksandrSiarohin/first-order-model) locally on your own machine (not covered in this tutorial but you can go [here](https://www.youtube.com/watch?v=ICvNnrWKHmc) to follow a tutorial), or (4) create another Google account and try again.

If you click "Connect Without GPU" then, later on, you'll encounter the following error:

![Error, no GPU](https://dev-to-uploads.s3.amazonaws.com/i/hknos7rvw63kictqmpy2.png)

## Creating your own deepfakes

Let's get started creating our own deepfakes.

### (Step 1) Cloning the Repo

Once you are signed in, you'll want to hover over the brackets under the "Clone Repository" header.

![Play button](https://dev-to-uploads.s3.amazonaws.com/i/vvub12tzbsvtd7v3ghqz.png)

You'll want to click on that play button to clone their repository.

### (Step 2) Change your directory

Once you finish cloning the repository, you'll want to change your current directory to "first-order-model" by clicking on the next play button like so:

![cd into first-order-model](https://dev-to-uploads.s3.amazonaws.com/i/k9lnrzzp5f28i4ekvcbc.png)

### (Step 3) Mounting your Google drive folder on Colab

Next, you'll want to mount your google drive folder on the colab by clicking the next play button.

![mounting](https://dev-to-uploads.s3.amazonaws.com/i/yz5x2v30tx7607l0q8jr.png)

Before this can actually happen however, you have to click the link allowing the permission to do so:

![Click on the link](https://dev-to-uploads.s3.amazonaws.com/i/6v89f7gdoxxcgxynm9bf.png)

Then you'll be prompted to sign in to your Google account again. Sign in to the same google account you originally signed into since starting this tutorial.

You will then see the following page:

![Auth code](https://dev-to-uploads.s3.amazonaws.com/i/ai5rs24r3dyyuiuht46f.png)

Copy and paste the authorization code into the colab like so and hit enter:

![Pasting auth code](https://dev-to-uploads.s3.amazonaws.com/i/g7rv8ffv334ul8v6uwli.png)

### (Step 4) Downloading the checkpoint (".pth.tar") files

Now you'll want to click on the following link:

![Link for downloading .pth.tar files](https://dev-to-uploads.s3.amazonaws.com/i/u4ixlh6zn20izcrl79mn.png)

You'll then get sent to a Google drive that will have several files.

![Drive with .tar files](https://dev-to-uploads.s3.amazonaws.com/i/ytnwffk1lble894u1mg9.png)

You only need to download the files called "vox-adv-cpk.pth.tar" and "vox-cpk.pth.tar" but I would also suggest you download a video and an image from here too.

For the purposes of this tutorial, I'll be downloading the aforementioned files as well as "05.png," which is an image of The Mona Lisa, and "10.mp4," which is a video of Leonardo DiCaprio's face.

*Downloading the files may take some time so just be patient.*

### (Step 5) Create a folder called "first-order-model-motion" in your Google Drive

Now you'll want to navigate to your Google Drive and create a folder called "first-order-motion-model" like so:

![Creating a folder in your Google Drive](https://dev-to-uploads.s3.amazonaws.com/i/57o5qse378d3kvesjkkw.png)

It's in this folder that you'll want to upload the files you just downloaded.

*Note: You can also upload your own video and images but just make sure they are cropped to 256px by 256px.*

*For the purposes of this tutorial, we'll just be using an image of The Mona Lisa and  a video of Leonardo DiCaprio's face.*

![Uploaded files](https://dev-to-uploads.s3.amazonaws.com/i/scgwq1ikswlthaqmxrst.png)

*This will also take some time so just be patient.*

### (Step 6) Loading your image and video

Now you want to go back to the Google Colab and under the "Load driving video and source image" header, make sure that 'source_image' and 'driving_video' point to the image and video you uploaded to your google drive.

![Checking paths](https://dev-to-uploads.s3.amazonaws.com/i/bw5lru7yxgt96kl2lc4a.png)

*Just make sure that the ending of the path has the correct name, i.e. '.../your_image_file.png' and '.../your_video_file.mp4'*

Now you want to go ahead and click the play button.

![Loading your own video and image](https://dev-to-uploads.s3.amazonaws.com/i/o6nllp0sjsqkj0psyy6u.png)

This will take a couple of seconds but once that's done, scroll down and you should see something like this

![Mona Lisa and DiCaprio](https://dev-to-uploads.s3.amazonaws.com/i/b0c6k9npdb579vwvc3zf.png)

### (Step 7) Creating the model and loading the checkpoints

If you scroll down a bit further you should see the following:

![Creating the model](https://dev-to-uploads.s3.amazonaws.com/i/ri6cfp55uew94dh2aygb.png)

*In the image above you see a square icon because I was already running it but you should see a play icon.*

Click on the play button and wait for it to finish.

### (Step 8) Creating the deepfake

Now is the moment you've been waiting for, actually creating the deepfake.

Scroll down until you see the header "Perform image animation" and click on the play button like so:

![Creating the deepfake](https://dev-to-uploads.s3.amazonaws.com/i/um6p65gim6k3vbdbfpiq.png)

Now you'll have to wait a little more but once that finished you should see something like the following:

![Deepfake](https://dev-to-uploads.s3.amazonaws.com/i/80tzkgttu49a6dz6iqwp.gif)

Congrats! You just created your first deepfake!

### (Step 9) Saving your deepfake

Now to actually save it, hover over the video and you should see an icon with three vertical dots.

![Dotted icon](https://dev-to-uploads.s3.amazonaws.com/i/dzaojb3jbf10j94012ny.png)

Click on the icon with three vertical dots and then click download.

![Downloading the deepfake](https://dev-to-uploads.s3.amazonaws.com/i/utstvmznfop85mvvgxd8.png)

And voila, you're done!

## Errors

If you encounter any errors, you can try to reset the runtime by doing the following:

Click on the "Runtime" tab.

![Runtime 1](https://dev-to-uploads.s3.amazonaws.com/i/qu5gr6xfsve9t8rmxa26.png)

Click on "Factory reset runtime."

![Runtime 2](https://dev-to-uploads.s3.amazonaws.com/i/bede4c7qkc70psb9q441.png)

Click "Yes" and reload the page.

![Runtime 3](https://dev-to-uploads.s3.amazonaws.com/i/bjqb4doh49uicqncuem0.png)

If you still encounter errors you can watch this video [here](https://www.youtube.com/watch?v=YsghMCWSa90).

## Using your own image

To use your own image, simply grab any facial image and crop it to 256px by 256px.

Also, make sure it's saved in the ".png" format.

*Other image types may work, such as .jpg, but .png will give you the best results, at least in my experience.*

## Using your own video

If you want to use your own video you also have to crop it to 256px by 256px.

The Google colab provides a tool for you to do this.

*Before we can actually crop our own video, we have to upload our video to our Google drive.*

Scroll down to the header that says "Running on your data"

![Running on your data](https://dev-to-uploads.s3.amazonaws.com/i/equi8fffwyoi0awzb9fj.png)

You'll want to paste the following line making sure you replace ".../my_video_file.mp4" to match your file name.

```
!ffmpeg -i /content/gdrive/My\ Drive/first-order-motion-model/my_video_file.mp4 -s 256x256 -c:a copy /content/gdrive/My\ Drive/first-order-motion-model/result.mp4
```
Then you should see a video called "result.mp4" in your google drive.

You can then use this video in step 6 and onward making sure that you use the name "result.mp4" for the video.

*The video result can be a hit or miss. I'd suggest you crop the video yourself using video editing software.*

## Video tutorials

[6-minute video tutorial](https://www.youtube.com/watch?v=peOKeRBU_uQ).
 - *In this tutorial, he makes you paste the following line of code: '!pip install PyYAML==5.3.1' at the beginning of Step 1. This line is not necessary.*

[20-minute video tutorial](https://www.youtube.com/watch?v=zZr3EHLBm4g).
  
[Creating a deepfake without using Google Colab](https://www.youtube.com/watch?v=ICvNnrWKHmc).