Creating Your Own Deepfake using iperov’s DeepFaceLab (2024)

Ever since I learned about Deepfakes on the internet, I have been really interested in how they worked and how it was done. The act of being able to take any video on youtube, download it, and put someone else’s face is comic gold to me.

The goal of this blog post is to show all the learnings I’ve gathered and condense them into a quick read for the anyone to be able to have a sense of direction as to where to go into making a Deepfake themselves.

A Deepfake is basically altering a video recording of someone; whether it’s a political figure, an actor, or someone famous, and then grabbing another person’s face and swapping it with the original video recording. The way it’s done is via training Neural Networks, feeding it various images of the ‘source’ and ‘destination’ faces. (We’ll dive deeper into this topic below)

Creating Your Own Deepfake using iperov’s DeepFaceLab (2)

First we need to head on over to Github and install one of DeepFaceLab’s Prebuilt Windows Releases. https://github.com/iperov/DeepFaceLab/blob/master/doc/doc_prebuilt_windows_app.md At this moment, this is available only on Windows machines. The way that these prebuilt releases work is via running windows batch files.

Once downloaded, please run the .exe file and choose the target location where the you’d like to extract its contents.

Creating Your Own Deepfake using iperov’s DeepFaceLab (3)

Once installed you will be greeting with a lot of batch files. Not to worry, I will highlight the important ones.

Creating Your Own Deepfake using iperov’s DeepFaceLab (4)

The workspace folder is the most important one to note. This is the folder where all the magic will happen. It contains three folders and two video files:

Creating Your Own Deepfake using iperov’s DeepFaceLab (5)
  1. “data_dst”
  • dst = destination: the folder where the original video files will live. When the project is complete, it will include two sub-folders: “aligned” and “merged”. We will talk about these later on.

2. “data_src”

  • src = source: the folder where the face of the ‘fake’ will live. When the project is complete, it will include one sub-folder: “aligned”.

3) “model”

  • model: this folder will contain the training model files used for the neural network.

4) “data_dst.mp4”

  • This file is the destination video where we will swap the fake face with.

5) “data_src.mp4”

  • This is the source video file where we will collect and gather the face image assets from to train our neural network.

There are a total of 8 batch files we need to run. Remember all those batch files we saw before? Now we will go more into depth with the ones we want to concentrate on.

1) “1) clear workspace.bat” this will clear all the contents in the workspace folder. This would usually be executed if the workspace folder contains a previous project. (IMPORTANT: Make a backup of your workspace folder if you have items you care about. Once this is run, it will delete everything from it and recreate a blank workspace with the default folder structure as described above.)

2) “2) extract images from video data_src.bat” It will take the video from “data_src.mp4” and slice it up into images and save them to the “data_src” folder. We will be greeted with a couple of prompts. We will use the defaults, just press enter and use the defaults.

3) “3.2) extract images from video data_dst FULL FPS.bat” Same as step two, it will take “data_dst.mp4”, extract the images and saves them to the “data_dst” folder.

4) “4) data_src extract faces MT all GPU debug.bat” It will look at the “data_src” folder and extract all the faces from the video and saves them to the “aligned” folder. It runs a facial detection algorithm on each image inside the “data_src” folder, crops the faces and saves them to the “aligned” folder.

5) “5) data_dst extract faces MT all GPU .bat” Same as the previous step, but this time it’s for the “data_dst” folder.

Note: Steps four and five will be the image files we will be using to train our Neural Network model. Please go into each “aligned” folder and clean them so we have good sample sets. Remove image files that do not contain faces, misaligned faces, or artifacts that the facial recognition algorithm thought were faces.

6) “6) train H64.bat” This model is the quickest and least GPU/CPU intensive model to run. It’s not the best model to use, but we will get quick results that will help us get a better grasp at the workflow and how it all ties in together.

7) “7) convert H64.bat” This will read the trained model files in the “model” folder and create a new sub-folder called “merged” in the “data_dst” root folder. The “merge” folder will contain the “deepfake” images.

8) “8) converted to mp4.bat” This will convert the .png files in the “merge” folder into a video using the “data_dst.mp4” file as the source.

Congrats! You’ve just created your first deepfake!

DeepFaceLab’s docs on how to use DFL with more in-depth information: https://github.com/iperov/DeepFaceLab/blob/master/doc/manual_en_google_translated.pdf

Creating Your Own Deepfake using iperov’s DeepFaceLab (2024)
Top Articles
Latest Posts
Article information

Author: Gregorio Kreiger

Last Updated:

Views: 6299

Rating: 4.7 / 5 (57 voted)

Reviews: 88% of readers found this page helpful

Author information

Name: Gregorio Kreiger

Birthday: 1994-12-18

Address: 89212 Tracey Ramp, Sunside, MT 08453-0951

Phone: +9014805370218

Job: Customer Designer

Hobby: Mountain biking, Orienteering, Hiking, Sewing, Backpacking, Mushroom hunting, Backpacking

Introduction: My name is Gregorio Kreiger, I am a tender, brainy, enthusiastic, combative, agreeable, gentle, gentle person who loves writing and wants to share my knowledge and understanding with you.