The DeepFaceLab Tutorial (2024)

Oct 25th, 2019 by DFBlue
  • tutorial
  • guide
  • how to
  • deepfacelab
  • deepfakes

👀 Update 10/25/19: Added instructions for the new SAEHD model (amazing)

👽 Update 9/24/19: New post for AVATAR mode

Source and destination videos requirements

  • High resolution (4k webm is best, lower than 1080p is not recommended)
  • Faces not too far from camera and unobstructed
  • Multiple angles, facial expressions
  • Brightly and evenly lit
  • Faces should somewhat match (beard, hat, hair, skin color, shape, glasses)
  • Need at least 2 mins of good quality video, interview videos work well

Downloading the software

We will use DeepFaceLab to create the deepfakes. Another software, FaceSwap is also available, and will have a separate tutorial.

  • Download DeepFaceLab
    • Make sure to pick the right build for your GPU. If you don’t have a GPU, use the CLSSE build
    • Here’s the direct link
    • In that folder, you will find some pre-compiled face-sets. Go ahead and download one of them to get started quickly (otherwise you will have to build your own face-set from videos / images)
  • The downloaded .exe will extract and install the program to the location of your choosing.
    • A workspace folder will be created. This is the folder where all the action will happen.

Extracting faces from source video

  • Name the source video data_src and place it in the \workspace folder.
    • Most formats that ffmpeg supports will work
  • Run 2) extract images from video data_src
    • Use PNG (better quality)
    • FPS <= 10 that gets you at least 2000 images (4k-6k is ideal)
  • Run 4) data_src extract faces S3FD best GPU
    • Extracted faces saved to data_src\aligned.
  • Run 4.2.2) data_src sort by similar histogram
    • Groups similar detected faces together
  • Run 4.1) data_src check result
    • Delete faces that are not the right person, super blurry, cut off, upside down or sideways, or obstructed
  • Run 4.2.other) data_src util add landmarks debug images
    • New images with _debug suffix are created in data_src/aligned which allow you to see the detected facial landmarks
    • Look for faces where landmarks are misaligned and delete the _debug and original images for those
    • Once you’re done, delete all _debug images by using the search bar to filter for _debug
  • Run 4.2.6) data_src sort by final
    • Choose a target image number around 90% of your total faces

Extracting faces from destination video

You may choose to either extract from (1) the final video clip you want, or (2) one that is cut to include only the face you want to swap. If you choose 1, you may have to spend more time cleaning the extracted faces. If you choose 2 you will have to edit back the final video (and audio) after the swap.

  • Name your final video data_dst and put it in the \workspace folder
  • Run 3.2) extract PNG from video data_dst FULL FPS
  • Run 5) data_dst extract faces S3FD best GPU
  • Run 5.2) data_dst sort by similar histogram
  • Run 5.1) data_dst check results
    • Delete all faces that are not the target face to swap, or are the target face but upside down or sideways. Every face that you leave in will be swapped in the final video.
  • Run 5.1) data_dst check results debug
    • Delete any faces that are not correctly aligned or missing alignment, paying special attention to the jawline. We will manually align these frames in the next step.
  • Run 5) data_dst extract faces MANUAL RE-EXTRACT DELETED RESULTS DEBUG
    • We run this step to manually align frames that we deleted in the last step. The manually aligned faces will be automatically extracted and used for converting. You must manually align frames you want converted (swapped) even if it’s a lot of work. If you fail to do so, your swap will use the original face for those frames.
    • Manual alignment instructions:
      • For each face, move your cursor around until it aligns correctly onto the face
      • If it’s not aligning, use the mouse scroll wheel / zoom to change the size of the boxes
      • When alignment is correct, hit enter
      • Go back and forth with , and .. If you don’t want to align a frame just skip it with .
      • Mouse left click will lock/unlock landmarks. You can either lock it by clicking or hitting enter.

Training

Run 6) train SAEHD

SettingValueNotes
iterations100000Or until previews are sharp with eyes and teeth details.
resolution128Increasing resolution requires significant VRAM increase
face_typef
learn_masky
optimizer_mode2 or 3Modes 2/3 place work on the gpu and system memory. For a 8gb card you can place on mode 3 and still most likely be able to do 160 res fakes with small batch size.
architecturedf
ae_dims512Reduce if less GPU memory (256)
ed_ch_dims21Reduce if less GPU memory
random_warpy
truefacen
face_style_power0Can enable if you want to morph src more to dst. But disable after 15k iterations.
bg_style_power10Turn off at 15k iterations. Styles on consume \~30% more vram so you will need to change batch size accordingly.
color_transfervariesTry all modes in the interactive converter
clipgradn
batch_size8Higher if you don't run out of memory
sort_by_yawnNo, unless you have very few src faces
random_flipy
For an NVIDIA GTX 1080 8gb GPU

Optional: History timelapse

Before converting, you can make a timelapse of the preview history (if you saved it during training). Do this only if you understand what ffmpeg is.

> cd \workspace\model\SAEHD_history> ffmpeg -r 120 -f image2 -s 1280x720 -i %05d0.jpg -vcodec libx264 -crf 25 -pix_fmt yuv420p history.mp4

Convert

  • Run 7) convert SAEHD

Use the interactive converter and memorize the shortcut keys, it will speed up the process a lot.

SettingValueNotes
interactive_converteryDefinitely use the interactive converter since you can try out all the different settings before converting all the frames
modeoverlay
mask_modelearned
erode_modifier0-50If src face is bleeding outside the edge of dst face increase this to "erode" away the src face on the outside
blur_modifier10-200The more similar the face the lower you can set erode and blur and get great results.
motion_blur0
color_transferebsTry all of them, can even use different ones for different scenes / lighting
sharpen_modebox
sharpen_amount1-3
super_resolutionRankSRGANEnhances detail, especially around the eyes
color_degrade_powern
export_alpha_masknOutputs transparent PNGs for use in post-production tools if you need it
  • While conversion is running, you can preview the final images data_dst\merged folder to make sure it’s correct. If it’s not, just close the convert window, delete /merged and start conversion again.
  • Run 8) converted to mp4
    • Bitrate of 3-8 is sufficient for most

Done 🤡

Contributions by DFBlue, PlanetOfTheFakes

Follow us on Twitter @dfblue or Reddit u/deepfakeblue to keep up with everything that is going on in the world of deepfakes. Think Blue.

The DeepFaceLab Tutorial (2024)

FAQs

Are deepfakes illegal? ›

There are no federal laws banning deepfake p*rn, but several bills have been introduced in Congress, including the AI Labeling Act of 2023 and the DEFIANCE Act of 2024. Neither has moved out of committee.

Is DeepFaceLab legit? ›

DeepFaceLab is an open source project that can be found on GitHub. For a couple of years now, it has been possible to use this software to create deepfakes. The quality of the deepfake that the software makes depends partly on the quality of the data available, but mainly on the skill of the user.

How to solve deepfakes? ›

To combat such abuses, technologies can be used to detect deepfakes or enable authentication of genuine media. Detection technologies aim to identify fake media without needing to compare it to the original, unaltered media. These technologies typically use a form of AI known as machine learning.

Why is deepfake detection difficult? ›

Many tools for deepfake detection — especially in academic fields — rely on old data that doesn't match the current crop of deepfake production tools, he said. “These kinds of detection tools can achieve very good performance on certain datasets, but cannot perform that well in the real world,” Zhang said.

Can you sue for deepfakes? ›

The Disrupt Explicit Forged Images and Non-Consensual Edits, or DEFIANCE Act, allows victims to sue if those who created the deepfakes knew, or “recklessly disregarded” that the victim did not consent to its making.

How harmful are deepfakes? ›

Not only has this technology created confusion, skepticism, and the spread of misinformation, deepfakes also pose a threat to privacy and security. With the ability to convincingly impersonate anyone, cybercriminals can orchestrate phishing scams or identity theft operations with alarming precision.

How to spot AI fakes? ›

How to identify AI-generated videos
  1. Look out for strange shadows, blurs, or light flickers. In some AI-generated videos, shadows or light may appear to flicker only on the face of the person speaking or possibly only in the background. ...
  2. Unnatural body language. This is another AI giveaway. ...
  3. Take a closer listen.

What percent of people fall for deepfakes? ›

A survey conducted by LocalCircles, a social media platform and pollster focusing on governance, public and consumer interest issues, revealed that according to 30 percent of citizens, 25 percent of all videos they watch are later found to be fake.

Is making deepfakes hard? ›

Creating a deepfake used to be a time-consuming, expensive process that required a high level of technical expertise. However, with the advent of machine learning algorithms, it's now possible to make a deepfake in just a few minutes using off-the-shelf software and a few dollars.

Can deepfakes be tracked? ›

As these generative artificial intelligence (AI) technologies become more common, researchers are now tracking their proliferation through a database of political deepfakes.

Which model is best for deepfake detection? ›

1. HyperVerge's deepfake detection. HyperVerge is a refined deepfake detection solution. With an AI model trained over 13 years and machine learning to provide comprehensive security, HyperVerge provides advanced deepfake detection, in addition to identity verification, facial recognition, and robust liveness checks.

Can AI detect fake voice? ›

NPR identified three deepfake audio detection providers — Pindrop Security, AI or Not and AI Voice Detector. Most claim their tools are over 90% accurate at differentiating between real audio and AI-generated audio. Pindrop only works with businesses, while the others are available for individuals to use.

What crime is deepfake? ›

The new offence builds on existing offences relating to such intimate image abuse including: the offence for sharing of intimate images (including deepfakes) which came into force on 31 January 2024 through section 188 of the OSA as an amendment introducing section 66B Sexual Offences Act 2003; and.

Are deepfakes detectable? ›

The Importance of Deepfake Detection

According to a recent study, humans can detect deepfake speech only 73% of the time. This study, out of the University of London with 529 participants, was one of the first to assess humans' ability to detect artificially-generated speech in a language other than English.

Are deepfakes identity theft? ›

By leveraging artificial intelligence, deepfakes enable fraudsters to clone your face, voice, and mannerisms to steal your identity.

Top Articles
Latest Posts
Article information

Author: Horacio Brakus JD

Last Updated:

Views: 5312

Rating: 4 / 5 (51 voted)

Reviews: 82% of readers found this page helpful

Author information

Name: Horacio Brakus JD

Birthday: 1999-08-21

Address: Apt. 524 43384 Minnie Prairie, South Edda, MA 62804

Phone: +5931039998219

Job: Sales Strategist

Hobby: Sculling, Kitesurfing, Orienteering, Painting, Computer programming, Creative writing, Scuba diving

Introduction: My name is Horacio Brakus JD, I am a lively, splendid, jolly, vivacious, vast, cheerful, agreeable person who loves writing and wants to share my knowledge and understanding with you.