How to Make a Deepfake With AI (it’s Easier Than You Think)

by Santis Projects in Circuits > Software

2559 Views, 4 Favorites, 0 Comments

How to Make a Deepfake With AI (it’s Easier Than You Think)

Cover.png

Have you ever seen a video where one person's face is swapped for another? That's the definition of deepfake, a video of a person in which their face has been digitally altered to look like another person, often used for malicious purposes or to spread false information. But please, if you follow this tutorial and learn how to make your own Deepfake with artificial intelligence, do not use it for malicious purposes or to spread false information. Take it as a fun photo editing tool.

Now let's talk a little about this type of artificial intelligence. The Google Colab to be used in this tutorial is a simplification from a December 2019 post. This is the original project page:

https://aliaksandrsiarohin.github.io/first-order-model-website/

The process is very fast because it was previously trained. In artificial intelligence, training usually takes the longest, in addition to obtaining the training data. Specifically, it is trained to search for key points in the input video based on one of the following categories: faces, human body movements, stickers, or a robotic arm. But in this tutorial the model we will use will be the face model.

Once the process begins, it uses the model to look for key points in each frame of the video, therefore, it will map where the eyes are and where they are looking, where the mouth is, if it is open or closed, and so on. This process is called extraction.

The second step is the most interesting, as it will seek to map the movement of the key points in the image we give it, and transform the image by stretching and contracting sections to achieve this. In addition to stretching and contracting, he pays special attention to eye movement, mouth opening, but does not correctly recognize sticking out his tongue. Also the head movement is interesting. If the head is moving to see the other side, for example the other ear or to show part of the background that is not visible in the image it is supposed to show, this net does a very good job. It's definitely not perfect, but it does a pretty admirable job.

Once you have understood all the theoretical part, let the practice begin.

Supplies

The requirements are:

  • An explorer
  • Internet
  • A Google account: if you are worried about security, it is better to do it in a Google account that you create just for this.
  • Download the .tar file below: you don't need to run it, just drag it directly to your Google Drive and you can delete it from your computer.

Link:

https://drive.google.com/file/d/1-VPALvBx4Ev6RPDmCy5MU1_8xw6NJpJd/view?usp=sharing

  • A video of you talking to the camera: the only restriction is that the video be square, preferably a small resolution, around 320 or 500 pixels. Try not to move too much, but some expressions can be made, such as moving your eyes, opening your mouth and moving a little on the sides, but not too much. You have to upload this video to your Google Drive.
  • The image of the person you want to personify: it can be a famous person or a family member or even a drawing. It is important that his mouth is not open, he is not making exaggerated gestures and has a relatively simple background. It have to be serious, but not angry. You have to upload this video to your Google Drive.

Clarification: It is recommended to upload the three files (the .tar, the image and the video) to a folder called “deepfake” in your Google Drive so that it is easier to work with them later.

Open the Colab and Make a Copy to Your Drive

Step 1 Image 1.png

The first step is to open the link to the Google Colab and make a copy to your drive so you can modify it. If you've never used Google Colab, it's basically for programming and running programs in a browser. In Google Colab you can make use of a cloud computer that gives you access to GPU and a good amount of RAM.

Link:

https://colab.research.google.com/drive/1gKThoPUlSz42_NVT8CxJdnI6tphrY28q?usp=sharing

Clone the Creators GitHub Repository

Step 2 Image 1.png

The second step is to run the first cell to clone the creators' GitHub repository.

Put Ourselves Into the Github Folder That We Cloned

Step 3 Image 1.png

The third step is to run the second cell to put ourselves into it the Github folder that we cloned.

Mount Your Google Drive in This Colab

Step 4 Image 1.png

The fourth step is to mount your Google Drive folder on this Colab. When you run this cell, a banner will appear that you must accept. Then a window will appear in which by accepting you will be approving Google Colab to access your Google Drive. That's all you have to do.

Enter the Path of the .Tar That You Have Uploaded to Google Drive

Step 5 Image 1.png

The fifth step is to enter the path of the .tar that you have uploaded to Google drive. In the image you can see where to insert it. If you haven't done it yet, here below is the file that you have to download and upload to your Drive. Once this cell and the ones above are executed, they are reused for all the times you want to execute the one below.

Link:

https://drive.google.com/file/d/1-VPALvBx4Ev6RPDmCy5MU1_8xw6NJpJd/view?usp=sharing

Enter the Path of the Image You Want to Animate, the One of the Reference Video and Run This Cell.

Step 6 Image 1.png
descarga.gif

And sixth step is to enter the path of the image you want to animate, the one of the reference video and execute this cell. In the image you can see where you have to enter these paths.

Internally, the artificial intelligence will manipulate the input image many times with the extraction that I make of each frame of the video, so it can be said that an image, a photograph, is being edited. When it finishes processing, we already have our own deepfake ready!

If you get an error when executing the last cell, try a lower resolution or shorter video, and it will surely work correctly.

Since this model exports it without audio, if you want you can put it in a video editor with the original audio, and since this program exports it a bit slower, put it at 1.25x.

To download the video, click on the three dots in the lower right corner and then on "Download".

As you can see it was quite simple. It is very important that your friends, acquaintances and family know that it is getting easier to do this kind of thing. We have to be very critical of everything we see, so that we are not deceived, but it is also very important that, as we said at the beginning, you do not use this tool to deceive or harm anyone. I hope you enjoyed this project and that you may have achieved what you wanted to do!