The DeepFaceLab Tutorial

Oct 25th, 2019 by DFBlue

🔥👉 New: Create NFTs from your Instagram posts and sell them: https://cryptogram.is/


👀 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

Downloading the software

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

Extracting faces from source video

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.

Training

Run 6) train SAEHD

Setting Value Notes
iterations 100000 Or until previews are sharp with eyes and teeth details.
resolution 128 Increasing resolution requires significant VRAM increase
face_type f
learn_mask y
optimizer_mode 2 or 3 Modes 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.
architecture df
ae_dims 512 Reduce if less GPU memory (256)
ed_ch_dims 21 Reduce if less GPU memory
random_warp y
trueface n
face_style_power 0 Can enable if you want to morph src more to dst. But disable after 15k iterations.
bg_style_power 10 Turn off at 15k iterations. Styles on consume \~30% more vram so you will need to change batch size accordingly.
color_transfer varies Try all modes in the interactive converter
clipgrad n
batch_size 8 Higher if you don't run out of memory
sort_by_yaw n No, unless you have very few src faces
random_flip y
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

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

Setting Value Notes
interactive_converter y Definitely use the interactive converter since you can try out all the different settings before converting all the frames
mode overlay
mask_mode learned
erode_modifier 0-50 If src face is bleeding outside the edge of dst face increase this to "erode" away the src face on the outside
blur_modifier 10-200 The more similar the face the lower you can set erode and blur and get great results.
motion_blur 0
color_transfer ebs Try all of them, can even use different ones for different scenes / lighting
sharpen_mode box
sharpen_amount 1-3
super_resolution RankSRGAN Enhances detail, especially around the eyes
color_degrade_power n
export_alpha_mask n Outputs transparent PNGs for use in post-production tools if you need it

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.