MrDeepFakes Forums
  • New and improved dark forum theme!
  • Guests can now comment on videos on the tube.
   
Total Likes Received: 335 (0.7 per day | 9.02 percent of total 3715)
(Find All Threads Liked ForFind All Posts Liked For) Total Likes Given: 26 (0.05 per day | 0.69 percent of total 3747)
(Find All Liked ThreadsFind All Liked Posts)

tutsmybarreh
(Moderator/Deepfake creator)

Registration Date: 03-17-2019
Date of Birth: Not Specified
Local Time: 07-07-2020 at 11:29 AM
Status:

tutsmybarreh's Most Liked Post
Post Subject Numbers of Likes
[GUIDE] - DeepFaceLab 2.0 EXPLAINED AND TUTORIALS (recommended) 11
Thread Subject Forum Name
[GUIDE] - DeepFaceLab 2.0 EXPLAINED AND TUTORIALS (recommended) Guides and Tutorials
Post Message
DeepFaceLab 2.0 Guide/Tutorial

[Image: You are not allowed to view links. Register or Login to view.]

NOTE: This thread is meant to be just a guide.

The only types of posts/questions allowed here are ones about the guide itself - suggestions on what to add to it and what's not clear.
If you have a question about techniques/workflows, want to complain or just talk in general and share something about the process of using DFL 2.0 please post in this thread:
You are not allowed to view links. Register or Login to view.

What is DeepFaceLab 2.0?

DeepFaceLab 2.0 is a tool/app utilizing machine learning to swap faces in videos.

What's the difference between 1.0 and 2.0? What's new in DFL 2.0?

At the core DFL 2.0 is very similar to 1.0 but it was rewritten and optimized to run much faster and offer better quality at the cost of compatibility.
Because of it, AMD cards are no longer supported and new models (based on SAE/SAEHD and Quick96) are incompatible with previous versions. However any datasets that have been extracted with later versions of DFL 1.0 can be still used in 2.0.

SAEHD DFL 2.0 Spreadsheet with users model settings: You are not allowed to view links. Register or Login to view.
DFL 2.0  trained and pretrained models sharing thread: You are not allowed to view links. Register or Login to view.

"Official" DFL paper: You are not allowed to view links. Register or Login to view.

He is a list of main features and changes in 2.0:
  • Available as standalone app.
  • Includes 2 models: SAEHD and Quick 96.
  • Support for multi-GPU configurations.
  • Increased performance during faceset (dataset) extraction, training and merging thanks to better optimization (compared to DFL 1.0)
  • Faceset enhancer - for upscaling/enhancing detail of source faceset (dataset).
  • GAN Power option - Generative Adversarial Network training, which enhances details of the face.
  • TrueFace Power option - variable face discrimination for better likeness to the source.
  • Ability to choose which GPU to use for each step (extraction, training, merging).
  • Ability to quickly rename, delete and create new models within the command line window.
  • Merging process now also outputs mask images for post process work in external video editing software.
  • Face landmark/position data embedded within dataset/faceset image files with option to extract embedded info for dataset modifications.
  • Training preview window.
  • Interactive converter.
  • Debug (face landmark preview) option for source and destination (data_src/dst) datasets.
  • Faceset (dataset) extraction with S3FD and/or manual extraction.
  • Training at any resolution in increments of 16. Possibility of training models at resolutions up to 640x640.
  • Multiple architectures (DF, LIAE, -U, -D and -UD variants)
DeepFaceLab 2.0 is compatible with NVIDIA GPUs and CPUs, no AMD support anymore, if you want to train on AMD GPUs - DFL 1.0 can do it but it's no longer supported/updated.
DFL 2.0 requires Nvidia GPUs that support at least CUDA Compute Compability version 3.0
CUDA Compute Capability list: You are not allowed to view links. Register or Login to view.

DOWNLOAD:

GitHub page (contains newest version as well as all current updates): You are not allowed to view links. Register or Login to view.
Stable releases can be found here: You are not allowed to view links. Register or Login to view.

If you don't have an NVIDIA GPU and your CPU doesn't let you train in any reasonable time or you don't want to use DFL 1.0 with your AMD GPU consider using Google Colab: You are not allowed to view links. Register or Login to view.

Explanation of all DFL functions:

DeepFaceLab 2.0 consists of selection of .bat files used to extract, train and merge (previously called convert) which are 3 main steps of creating a deepfake, they are located in the main folder along with two subfolders:
  • _internal (that's where all the files necessary for DFLs to work are)
  • workspace (this is where your models, videos, facesets (datasets) and final video outputs are
Before we go into the main guide part here is some terminology (folders are written with "quotations")

Faceset (dataset) - is a set of images that have been extracted (or aligned with landmarks) from frames (extracted from video) or photos.

There are two datasets being used in DFL 2.0 and they are data_dst and data_src:

- data_dst is a folder that holds frames extracted from data_dst.mp4 file - that's the target video onto which we swap faces. It also contains 2 folders that are created after running face extraction from extracted frames:
"aligned" containing images of faces, 512x512 in size (with embedded facial landmarks data)
"aligned_debug" which contains original frames with landmarks overlayed on faces which is used to identify correctly/incorrectly aligned faces (and it doesn't take a part in training or merging process).
After cleaning up dataset (of false positives, incorrectly aligned faces and fixing them) it can be deleted to save space.

- data_src is a folder that holds frames extracted from data_src.mp4 file (that can be interview, movie, trailer, etc) or where you can place images of your source - basically the person whose face you want to swap on target video. As with data_dst extraction, after extracting faces from frames/pictures 2 folders are created:
"aligned" containing images of faces, 512x512 in size (with embedded facial landmarks data)
"aligned_debug" this folder by default is empty and doesn't contain any preview frames with landmarks like during extraction of data_dst, if you want these - you need to select yes (y) when starting extraction to confirm you want these generated to check if all faces are correctly extracted and aligned.

Before you get to extract faces however you must have something to extract them from:
- for data_dst you should prepare the target (destination) video and name it data_dst.mp4
- for data_src you should either prepare the source video (as in examples above) and name it data_src.mp4 or prepare images in jpg or png format.
The process of extracting frames from video is also called extraction so for the rest of the guide/tutorial I'll be referring to both processes as "face extraction" and "frame extraction".

As mentioned at the beginning all of that data is stored in the "workspace" folder, that's where both data_src/dst.mp4 files, both "data_src/dst" folders are (with extracted frames and "aligned"/"aligned_debug" folders for extracted/aligned faces) and the "model" folder where model files are stored.

Options are grouped based on the function they do.

1. Workspace cleanup/deletion:

1) Clear Workspace - self explanatory, it deletes all data from the "workspace" folder, feel free to delete this .bat file to prevent accidental removal of important files you will be storing in the "workspace" folder

2. Frames extraction from source video (data_src.mp4):

2) Extract images from video data_src - extracts frames from data_src.mp4 video file and puts them into automatically created "data_src" folder, available options:
- FPS - skip for videos default frame rate, enter numerical value for other frame rate (for example entering 5 will only render the video as it was 5 frames per second, meaning less frames will be extracted)
- JPG/PNG - choose the format of extracted frames, jpgs are smaller and generally have good enough quality so they are recommended, pngs are large and don't offer significantly higher quality but they are an option.

3. Video cutting (optional):

3) cut video (drop video on me) - allows to quickly cut any video to desired length by dropping it onto that .bat file. Useful if you don't have video editing software and want to quickly cut the video, options:
From time - start of the video
End time - end of the video
Audio track - leave at default
Bitrate - let's you change bitrate (quality) of the video - also best to leave at default

3. Frames extraction from destination video (data_dst.mp4):

3) extract images from video data_dst FULL FPS - extracts frames from data_dst.mp4 video file and puts them into automatically created "data_dst" folder, available options:
- JPG/PNG - same as in 2).

4. Data_src faces extraction/alignment:

First stage of preparing source dataset is to align the landmarks and produce 512x512 face images from the extracted frames located inside "data_src" folder.

There are 2 options:
4) data_src faceset extract MANUAL - manual extraction
4) data_src faceset extract
- automated extraction using S3FD algorithm

Available options for both S3FD and MANUAL extractor are:
- choosing coverage area of extraction depending on face type of the model you want to train:
a) full face (for half, mid-half and full face)
b) whole face (for whole face but also works with others)
c) head (for head type of model)

- choosing which gpu (or cpu) to use for faces extraction/alignment process.
- choosing whether to generate "aligned_debug" folder or not.

4. Data_src cleanup:

After that is finished next step is to clean the source faceset/dataset of false positives/incorrectly aligned faces, for a detailed info check this thread: You are not allowed to view links. Register or Login to view.

4.1) data_src view aligned result - opens up external app that allows to quickly go through the contents of "data_src/aligned" folder for false positives and incorrectly aligned source faces as well as faces of other people so you can delete them.

4.2) data_src sort - contains various sorting algorithms to help you find unwanted faces, these are the available options:

[0] blur
[1] face yaw direction
[2] face pitch direction
[3] face rect size in source image
[4] histogram similarity
[5] histogram dissimilarity
[6] brightness
[7] hue
[8] amount of black pixels
[9] original filename
[10] one face in image
[11] absolute pixel difference
[12] best faces
[13] best faces faster

4.2) data_src util add landmarks debug images - let's you generate "aligned_debug" folder after extracting faces (if you wanted to have it but forgot or didn't select the right option in the first place.

4.2) data_src util faceset enhance - uses special machine learning algorithm to upscale/enhance the look of faces in your dataset, useful if your dataset is a bit blurry or you want to make a sharp one have even more detail/texture.

4.2) data_src util faceset metadata restore and 4.2) data_src util faceset metadata save - let's you save and later restore embedded alignment data from your source faceset/dataset so you can edit some face images after you extracted them (for example sharpen them, edit out glasses, skin blemishes, color correct) without loosing alignment data and also so you don't need to re-extract them again.

EDITING ANY IMAGES FROM "ALIGNED" FOLDER WITHOUT THIS STEP WILL REMOVE THAT ALIGNMENT DATA AND THOSE PICTURES WON'T BE USABLE IN TRAINING, WHEN EDITING KEEP THE NAMES THE SAME, NO FLIPPING/ROTATION IS ALLOWED, ONLY SIMPLE EDITS LIKE COLOR CORRECTION, ETC.

4.2) data_src util faceset pack and 4.2) data_src util faceset unpack - packs/unpacks all faces from "aligned" folder into/from one file.

4.2.other) data_src util recover original filename - reverts names of face images back to original order/filename (after sorting).

5. Data_dst preparation:

Here steps are pretty much the same as with source dataset, with few exceptions, let's start with faces extraction/alignment process.
We still have Manual and S3FD extraction method but there is also one that combines both and a special manual extraction mode, "aligned_debug" folder is generated always.

5) data_dst faceset extract MANUAL RE-EXTRACT DELETED ALIGNED_DEBUG - manually extraction from frames deleted from "aligned_debug" folder. More on that in next step - Data_dst cleanup.
5) data_dst faceset extract MANUAL - manual extraction.
5) data_dst faceset extract + manual fix - automated extraction + manual one for frames where algorithm couldn't properly detect faces.
5) data_dst faceset extract - automated extraction using S3FD algorithm.

Available options for all extractor modes are:

- choosing coverage area of extraction depending on face type of the model you want to train:
a) full face (for half, mid-half and full face)
b) whole face (for whole face but also works with others)
c) head (for head type of model)

- choosing which GPU (or CPU) to use for faces extraction/alignment process.

5. Data_dst cleanup:

After we aligned data_dst faces we have to clean them up, similar to how we did it with source faceset/dataset we have a selection of sorting methods which I'm not going to explain as they work exactly the same as ones for src.
However cleaning up the destination dataset is different than source because we want to have all the faces aligned for all the frames where they are present - including obstructed ones which we can mark in the XSeg editor and then train our XSeg model which will mask them out - effectively making obstructions clearly visible over the learned faces, more on that in the XSeg stage below. There are couple of tools at our disposal for that:

5.1) data_dst view aligned results - let's you view the contents of "aligned" folder using external app (built into DFL) which offers quicker thumbnail generation than default windows explorer
5.1) data_dst view aligned_debug results - let's you quickly browse contents of "aligned_debug" folder to locate and delete any frames where our target person face has incorrectly aligned landmarks or where landmarks weren't placed at all (which means face wasn't detected at all). In general you use this to find if all your faces are properly extracted and aligned (if landmarks on some frames aren't lining up with the shape of the face or eyes/nose/mouth/eyebrows or are missing - they should be deleted so we can later manually re-extract/align them).
5.2) data_dst sort - same as with source faceset/dataset, this tool let's you sort all aligned faces within "data_dst/aligned" folder so that's it's easier to locate incorrectly aligned faces, false positives and faces of other people we don't want to train our model on/swap faces onto.
5.2) data_dst util faceset pack and 5.2) data_dst util faceset unpack - same as with source, let's you quickly pack entire dataset into one file.
5.2) data_dst util recover original filename - same as with source, restores original names/order of all aligned faces after sorting.

Now that you know your tools here is an example of my technique/workflow for cleaning up the data_dst dataset that guarantees 100% of faces extraction.

1. Start by sorting data_dst using 5.2) data_dst sort and select sorting by histogram, this will generally sort faces by their similarity in color/structure so it's likely to group similar ones together and separate any images that may contain rotated/zoomed in/out faces, as well as false positives and faces of other people and put them at either beginning/end of the list.
2. Delete all false positives, incorrectly aligned (rotated) and unwanted faces.
3. Revert the filenames/order to original one using 5.2) data_dst util recover original filename.
4. Go into the folder "aligned" insides your "data_dst" and use the following powershell command to remove _0 prefixes from filenames of aligned data_dst faces.

Quote:- hold shift while right clicking, open powershell and use this command:

get-childitem *.jpg | foreach {rename-item $_ $_.name.replace("_0","")}

- wait for the folder address to be displayed again, indicating completion of the process and close the window

5. Create a copy of the "aligned_debug" folder.
6. Once done, select all files (ctrl + a) from "aligned" and copy them to the "aligned_debug - copy" folder, hit replace, wait for it to finish and while all replaced files are still highlight/selected in the windows explorer delete them.
7. Go through remaining frames and remove all that don't contain any faces you want to manually extract
8. Copy the rest back to the original "aligned_debug" folder, hit replace, wait for it to finish and while all replaced files are still highlight/selected in the windows explorer delete them.
9. Now your "aligned_debug" folder contains only frames from which faces were correctly extracted and all frames from which extractor failed to correctly extract faces or did not extract them are gone which means you can run 5) data_dst extract full_face (or whole_face depending on which one you've used for the rest) MANUAL RE-EXTRACT DELETED ALIGNED_DEBUG to manually extract them. Before you do that you might want to run 5.1) data_dst view aligned_debug results to quickly scroll through the remaining "good" ones and see if landmarks look correct on all of them, if you spot some less ideal looking landmarks, feel free to delete them so you can extract them manually too.
10. Now you are done cleaning up your data_dst and all faces are extracted correctly.

More tips, workflows, bug fixes and frequent issues are explained in the FAQ:
You are not allowed to view links. Register or Login to view.You are not allowed to view links. Register or Login to view.

And in this thread there are some details on how to create source datasets, what to keep, what to delete and also in general how to clean source dataset (pretty much the same was as target/destination dataset) and how/where to share them with other users: You are not allowed to view links. Register or Login to view.

5.1: XSeg model training and faceset marking.

With XSeg model you can train your own mask segmentator of dst(and src) faces that will be used during merging to mask result faces and mask out obstructions as well as specify face and background area for style powers to work with whole face and head face type models.
There is no pretrained XSeg model (unlike the old FANseg model) so you need to create your own that will control how the result face is masked over your DST/target video during merging. XSeg is designed to let you create masks that best suit your datasets.
Such models can be also reused so when you start working on a new video you don't need to train the model from scratch but instead reuse existing one and instead feed it new marked faces. Both src and dst facesets/datasets can be marked thus giving you options of using XSeg-prd (src) and XSeg-dst and also combine them both and even combine both with learned mask, just like FANSeg (FAN-dst, FAN-prd, FAN-dst+prd, FAN-dst+prd+learned)
XSeg works with all face types such as full_face, whole_face and even head so you have full control of the face coverage and can also include/exclude hair and obstructions.
Workflow is fairly straightforward, it's the best solution for obtaining good quality masks without the need of using video editing software and creating masks manually via means of rotoscoping using software like Mocha Pro or built-in solutions in various video editing software.

New available .bat files/scripts are:

5.XSeg) data_dst mask for XSeg trainer - edit - label tool to define masked areas of the destination faces with XSeg polygons.
5.XSeg) data_dst mask for XSeg trainer - fetch - copies faces containing XSeg polygons to folder "aligned_xseg". Can be used to collect labeled faces so they can be reused in future XSeg model training.
5.XSeg) data_dst mask for XSeg trainer - remove - removes labeled XSeg polygons from the extracted frames.
5.XSeg) data_src mask for XSeg trainer - edit - label tool to define masked areas of the source faces with XSeg polygons.
5.XSeg) data_src mask for XSeg trainer - fetch - copies faces containing XSeg polygons to folder "aligned_xseg". Can be used to collect labeled faces so they can be reused in future XSeg model training.
5.XSeg) data_src mask for XSeg trainer - remove - removes labeled XSeg polygons from the extracted frames.
XSeg) train.bat - runs the training of the XSeg model.
5.XSeg.optional) trained mask for data_dst - apply - replaces default full_face mask derived from landmarks created during extraction with one from trained XSeg model, only needed if you plan on using face/background style power with obstructed faces.
5.XSeg.optional) trained mask for data_dst - remove - removes it
5.XSeg.optional) trained mask for data_src - apply - replaces default full_face mask derived from landmarks created during extraction with one from trained XSeg model, only needed if you plan on using face/background style power with obstructed faces.
5.XSeg.optional) trained mask for data_src - remove - removes it

Usage:

1. Train your model - self explanatory. Nothing changes about this stage, just run your model of any face_type you want to use. The exception being using style powers with whole face or head face type models - basically if you want to be able to use this feature during training of the face swapping model (Quick 96, SAEHD) you need to train your XSeg model first and then apply trained masks (SRC and DST) to both datasets, otherwise this feature will not work, reason for this is that in order for it to work it must know where face and background is, the default masks used when training are derived from landmarks created during faces extraction and they only cover full face area - hence they can't be used with whole face and head face type models.

2. 5.XSeg) data_dst mask for XSeg trainer - edit - label/mask DST faces.

Read tooltips/description on the buttons to know their function (en/ru/zn languages are supported) and mask faces using include and/or exclude polygon mode.

Mask 50 to 100 different DST faces, you don't need to mask faces for every frame of dst but only those where the face looks significantly different, for example:

- has closed eyes/different facial expression
- face/head has changed direction/angle
- lighting condition/direction is different

The more various faces you mask, the better quality masks Xseg model will generate for you.
Start masking from the upper left area and follow the clockwise direction and keep the same logic of masking for all frames, for example:

- the same approximated jaw line of the side faces, where the jaw is not visible
- the same hair line

Once you finish marking (masking) DST faces hit Esc to save them, then you can move on to training your model if you are only gonna use XSeg-DST.

If you want to also user XSeg-PRD in the merger you need to run mark/mask SRC faces using SRC labeling tool: 5.XSeg) data_src mask for XSeg trainer - edit

2.1 Masking obstructions

While masking faces you will also probably want to mask out/exclude obstructions so that they are visible in the final video above the result face, to do so you can either:
- not include obstructions in the main mask that defines face area and other bits you want to be swapped.
- use exclude poly mode to draw additional mask around the obstruction.

When masking obstructions you need to make sure you mark them in several frames according to the same rules as when masking faces with no obstructions, mark the obstruction (even if it doesn't change appearance/shape/position when face/head:
- changes angle
- facial expression changes
- lighting conditions change

If the obstruction is additionally changing shape and/or moving across the face you need to mark it few times, not all obstruction in every frame need to be marked though but still the more variety of different obstructions occur in various conditions - the more frames you will have to mark.

3. Run XSeg) train.bat - Train the XSeg model.

- When starting training for the first time you will see an option to select face type of the model to be used with (such as full face, whole face, head), select one that matches your trained model and start training.
- You can switch preview modes using space (there are 3 modes, DST training, SRC training and SRC+DST (distorted).
- To update preview progress press P.
- Esc to save and stop training.


During training check preview often, if some faces have wrong or glitchy/broken masks, run edit again and find those faces that cause issues and mask them, then resume training or start it again from scratch.

Restarting the training of XSeg model is only possible by deleting all 'model\XSeg_*' files. You can also move them to other folder.

New mask modes available in merger for whole_face:
XSeg-prd  - XSeg mask of predicted face - faces from src faceset should be labeled/masked.
XSeg-dst  - XSeg mask of dst face - faces from dst faceset should be labeled/masked.
XSeg-prd*XSeg-dst - the smallest area of both XSeg-prd and XSeg-dst masks - both src and dst faceset must be labeled/masked.

If workspace\model folder contains trained XSeg model, then merger will use it, otherwise you will get transparent mask by using XSeg-* mask modes.

Screenshots:


- editor

[Image: You are not allowed to view links. Register or Login to view.]

- trainer

[Image: You are not allowed to view links. Register or Login to view.]

- merger

[Image: You are not allowed to view links. Register or Login to view.]

6. Training:

There are currently 2 models to choose from for training:

SAEHD (6GB+): High Definition Styled AutoEncoder model - high end model for high end GPUs with at least 6GB of VRAM.

Features:
- runs at any resolution in increments of 16 up to 512x512 pixels
- half face, mid-half face, full face and whole face mode
- 6 architectures: DF, LIAE, each in 3 variants - regular, UHD and HD
- Adjustable batch size
- Adjustable model auto encoder, encoder, decoder and mask decoder dimensions
- Adjustable auto backup
- Preview history
- Target iteration
- Random face yaw flip setting
- Mask learning
- GPU Optimizer
- Learning dropout
- Random warp
- Adjustable GAN training power setting
- Adjustable True Face training power setting
- Adjustable Face and Background Style power setting
- Color transfer
- Gradient Clipping
- Pretrain mode

Quick96 (2-4GB): Simple model derived from SAE model - dedicated for low end GPUs with 2-4GB of VRAM.

Features:
- runs at 96x96 pixels resolutions
- full face mode
- batch size 4

Both models can generate good deepfakes but obviously SAEHD is the preferred and more powerful one.
If you want to test out your ideas Quick96 isn't a bad idea but of course you can still run SAEHD at the same setting or go even lower.
If you want to see what other people can achieve with various graphics cards, check this spreadsheet out where users can share their model settings:
You are not allowed to view links. Register or Login to view.You are not allowed to view links. Register or Login to view.
After you've checked other peoples settings and decided on a model you want to use you start it up using either one of those:

6) train SAEHD
6) train Quick96

Since Quick96 is not adjustable you will see the command window pop up and ask only 1 question - CPU or GPU (if you have more then it will let you choose either one of them or train with both).
SAEHD however will present you with more options to adjust.

In both cases first a command line window will appear where you input your model settings. On a first start will you will have access to all setting that are explained below, on startup of training with a model already trained and present in the "model" folder you will also receive a prompt where you can choose which model to train on (if you have more than one set of model files present in your "model" folder).
You will also always get a prompt to select which GPU or CPU you want to run the trainer on.

Second thing you will see once you startup is the preview window that looks like this:

[Image: You are not allowed to view links. Register or Login to view.]

Here is a more detailed explanation of all functions in order they are presented to the user upon starting training of a new model:

Note that some of these get locked and can't be changed once you start training due to way these models work, example of things that can't be changed later are:
- model resolution
- model architecture
- models dimensions (dims settings)
- face type


Autobackup every N hour ( 0..24 ?:help ) : self explanatory - let's you enable automatic backups of your model every N hours. Leaving it at 0 (default) will disable auto backups. Default value is 0 (disabled).

Target iteration : will stop training after certain amount of iterations is reached, for example if you want to train you model to only 100.000 iterations you should enter a value of 100000. Leaving it at 0 will make it run until you stop it manually. Default value is 0 (disabled).

Flip faces randomly ( y/n ?:help ) : Useful option in cases where you don't have all necessary angles of the persons face (source dataset) that you want to swap onto the target. For example if you have a target/destination video with person looking straight and to the right and your source only has faces looking straight and to the left you should enable this feature but bear in mind that because no face is symmetrical results may look less like src and also features on the source face (like beauty marks, scars, moles, etc.) will be mirrored. Default value is n (disabled).

Batch_size ( ?:help ) : Batch size settings affects how many faces are being compared to each other every each iteration. Lowest value is 2 and you can go as high as your GPU will allow which is affected by VRAM. The higher your models resolution, dimensions and the more features you enable the more VRAM will be needed and thus lower batch size will be possible. It's recommended to not use value below 4. Higher batch size will provide better quality at the cost of slower training (higher iteration time). For the intial stage it can be set lower to speed up generalization of the face and then increase once face is sufficiently trained.
How to guess what batch size to use? You can either use trial and error or help yourself by taking a look at what other people can achieve on their GPUs by checking out the DFL 2.0 spreadsheet: You are not allowed to view links. Register or Login to view.[url=https://mrdeepfakes.com/forums/thread-dfl-2-0-user-model-settings-spreadsheet]https://mrdeepfakes.com/forums/thread-dfl-2-0-user-model-settings-spreadsheet

Resolution ( 64-512 ?:help ) : here you set your models resolution, bear in mind this option cannot be changed during training. It affects the resolution of swapped faces, the higher model resolution - the more detailed the learned face will be but also training will be much heavier and longer. Resolution can be increased in increments of 16 from 64x64 to 512x512.

Face type ( h/mf/f/wf/head ?:help ) : this option let's you set the area of the face you want to train, there are 5 options - half face, mid-half face, full face, whole face and head:
a) Half face - only trains from mouth to eybrows but can in some cases cut of top or bottom of the face (eyebrows, chin, bit of mouth).

b) Mid-half face - aims to fix this issue by covering 30% larger portion of face compared to half face which should prevent most of the undesirable cut offs from occurring but they can still happen.
c) Full face - covers most of the face area, excluding forehead, can sometimes cut off a little bit of chin but this happens very rarely - most recommended when SRC and/or DST have hair covering forehead.
d) Whole face - expands that area even more to cover pretty much the whole face, including forehead and even a little bit of hair but this mode should be used when we want to make a swap of the entire face, excluding hair. Additional option for this face type is masked_training that let's you prioritize learning full face area of face first and then (after disabling) letting the model learn the rest of the face like forehead.
e) Head - is used to do a swap of the entire head, not suitable for subjects with long hair, works best if the source faceset/dataset comes from single source and both SRC and DST have short hair or one that doesn't change shape depending on the angle. Minimum recommended resolution for this face type is 224.

[Image: You are not allowed to view links. Register or Login to view.]

Example of whole face type face swap:

[Image: You are not allowed to view links. Register or Login to view.]

Example of head type face swap:

You are not allowed to view links. Register or Login to view.
AE architecture ( dfhd/liaehd/dfuhd/liaeuhd/df/liae ?:help ) : This option let's you choose between 2 main learning architectures DF and LIAE as well as their HD and UHD version which offer slightly better quality at the cost of performance.

DF and LIAE architectures are the base ones, both offering good quality with decent performance.

DF-U, [b]DF-UD, [/b]LIAE-U and LIAE- UD are additional architecture variants.

DF: This model architecture provides a more direct face swap, doesn't morph faces but requires that the source and target/destination face/head have similar face shape.
This model works best on frontal shots and requires that your source dataset has all the required angles, can produce worse results on side profiles.

LIAE: This model architecture isn't as strict when it comes to face/head shape similarity between source and target/destination but this model does morph the faces so it's recommended to have actual face features (eyes, nose, mouth, overall face structure) similar between source and target/destination. This model offers worse resemblance to source on frontal shots but can handle side profiles much better and is more forgiving when it comes to source faceset/dataset, often producing more refined face swaps with better color/lighting match.

-U: this variant aims to improve similarity/likness of trained result face to SRC dataset.

[b]-D: [/b]this variant aims to improve performance, it let's you train your model at twice the resolution with no extra computional cost (VRAM usage) and similar performance, for example train 256 resolution model at the same VRAM usage and speed (iteration time) as 128 resolution model. However it requires longer training, model must be pretrained first for optimal results and resolution must be changed by the value of 32 as opposed to 16 in other variants.

[b]-UD:
[/b]combines both variants for maximum likness and increased resolution/performance. Also requires longer training and model to be pretrained.

The next 4 options control models neural network dimensions which affect models ability to learn, modifying these can have big impact on performance and quality of the learned faces so they should be left at default.

AutoEncoder dimensions ( 32-1024 ?:help ) : Auto encoder dimensions settings, affects overall ability of the model to learn faces.
Encoder dimensions ( 16-256 ?:help ) : Encoder dimensions settings, affects ability of the model to learn general structure of the faces.
Decoder dimensions ( 16-256 ?:help ) : Decoder dimensions settings, affects ability of the model to learn fine detail.
Decoder mask dimensions ( 16-256 ?:help ) : Mask decoder dimensions settings, affects quality of the learned masks. May or may not affect some other aspects of training.
Since now learned mask is enabled always by default and can't be changed one may consider dropping this setting down to lower value to get better performance but detailed tests would have to be done to determine effects on quality of masks, learned faces and performance to determine if it's worth to change is from default value.

The changes in performance when changing each setting can have varying effects on performance and it's not possible to measure effect of each one on performance and quality without extensive training. Each one is set at certain default value that should offer optimal results and good compromise between training speed and quality.

Also when changing one parameter the other ones should be changed as well to keep the relations between them similar (for example if you drop Encoder and Decoder dimensions from 64 to 48 you could also decrease AutoEncoder dimension from 256 to 192-240). Feel free to experiment with various settings but if you want a better quality you're better off raising resolution than changing these.
If you want optimal results, keep them at default.
Eyes priority ( y/n ?:help ) : Attempts to fix problems with eye training especially on HD architecture variants like DFHD and LIAEHD by forcing the neural network to train eyes with higher priority.
Bear in mind that it does not guarantee the right eye direction, it only affects the details of the eyes and area around them. Example (before and after):
[Image: You are not allowed to view links. Register or Login to view.]

Place models and optimizer on GPU ( y/n ?:help ) : Enabling GPU optimizer puts all the load on your GPU which greatly improves performance (iteration time) but will lead to lower batch size, disabling this feature (False) will offload some work (optimizer) to CPU which decreases load on GPU (and VRAM usage) letting you achieve slightly higher batch size or run more taxing models (higher resolution or model dimensions) at the cost of training speed (longer iteration time).
Basically if you get OOM (out of memory) errors you should disable this feature and thus some work will be offloaded to your CPU and some data from GPUs VRAM to system RAM - you will be able to run your model without OOM errors and/or at higher batch size but at the cost of lowered performance. Default value is y (enabled).

Use learning rate dropout ( y/n/cpu ?:help ) : This feature should be only enabled at the very end of training and should not be enabled earlier when random warp of samples is still enabled. Once your model is fairly well trained and sharp it will let you get a bit more detail and sharpness at less iterations that it would normally take without it and also make the faces more stable and less jittery. To read more about how learning rate dropout works, google it, it's a general concept in machine learning but because of this it requires knowledge in this field to fully understand.
It can be used with other options enabled like TrueFace, GAN, Style Power, Color Transfer, etc.
Can be run on CPU, saves VRAM but causes iteration time to be 20% slower.

Use with caution, enabling it before the model is fully trained may cause it to never improve until you disable it and let the training continue with this feature disabled.

Enable random warp of samples ( y/n ?:help ) : Random warp of samples is a feature that used to be enabled all the time in the old SAE models of DFL 1.0 but now is optional, it's used to generalize a model so that it properly learns all the basic shapes, face features, structure of the face, expressions and so on but as long as it's enabled the model may have trouble learning the fine detail - because of it it's recommended to keep this feature enabled as long as your faces are still improving (by looking at decreasing loss values and preview window), once the face are trained fully and you want to get some more detail you should disable it and in few hundred-thousand iterations you should start to see more detail and with this feature disabled you carry on with training. Default value is y (enabled).

Uniform_yaw ( y/n ?:help ) : Helps with training of profile faces, forces model to train evenly on all faces depending on their yaw and prioritizes profile faces, may cause frontal faces to a bit train slower, enabled by default during pretraining, can be used similarly to random warp (at the beginning of the training process) or enabled later when faces are more or less trained and you want profile faces to look better and less blurry. Useful when your source dataset doesn't have many profile shots.

GAN power ( 0.0 .. 10.0 ?:help ) : GAN stands for Generative Adversarial Network and in case of DFL 2.0 it is implemented as an additional way of training on your datasets to get more detailed/sharp faces. This option is adjustable on a scale from 0.0 to 10.0 and it should only be enabled once the model is more or less done training (after you've disabled random warp of samples). It's recommeded to start at low value before going all the way to max to test out if the feature gives good results as it heavily depends on having a good and clean source dataset. If you get bad results you need to disable it and enable random warp of samples for some time so that the model can recover. Consider making a backup before enabling this feature. Default value is 0.0 (disabled). Start at low value like 0.5-1, never go all the way to something like 5-10. For long time it may appear grainy, noisy, with some artifacts, they can disappear but require longer training.

Here is an example before and after enabling GAN training:

Before:
You are not allowed to view links. Register or Login to view.]
After:
[Image: You are not allowed to view links. Register or Login to view.]
If it's hard to notice the difference in the 1st example open it up in a new window.

'True face' power. ( 0.0000 .. 1.0 ?:help ) : True face training with a variable power settings let's you set the model discriminator to higher or lower value, what this does is it tries to make the final face look more like src, as with GAN this feature should only be enabled once random warp is disabled and model is more or less fully trained and here you should also start at a low value and make sure your source dataset is clean and correctly aligned, if you get bad results you need to disable it and enable random warp of samples for some time so that the model can recover. Consider making a backup before enabling this feature. Default value is 0.0 (disabled). Never use value of 1.0, start at 0.001 and go up to 0.01-0.02, anything more than that can result in terrible artifacts, wrong face direction and odd lighting.

[Image: You are not allowed to view links. Register or Login to view.]

Face style power ( 0.0..100.0 ?:help ) and Background style power ( 0.0..100.0 ?:help ) : This variable setting controls style transfer of either face or background part of the image, it is used to transfer the style of your target/destination faces (data_dst) over to the final learned face which can improve quality and look of the final result after merging but high values can cause learned face to look more like data_dst than data_src. It basically will transfer some color/lighting information from DST to result face.
It's recommended to not use values higher than 10. Start with small values.
This feature has big performance impact and using it will increase iteration time and may require you to lower your batch size or disable gpu optimizer (Place models and optimizer on GPU). Consider making a backup before enabling this feature.

Examples of things that this option may do is transfer the style/color of lips, eyes, makeup, etc from data_dst to the final learned face and also carry over some features of the face (skin color, some textures or facial features). The stronger the settings - the more things or style will be transferred from data_dst to the final learned face. Default value is 0.0 (disabled).

Color transfer for src faceset ( none/rct/lct/mkl/idt/sot ?:help ) : this features is used to match the colors of your data_src to the data_dst so that the final result has similar skin color/tone to the data_dst and the final result after training doesn't change colors when face moves around (which may happen if various face angles were taken from various sources that contained different light conditions or were color graded differently). There are several options to choose from:

- rct (reinhard color transfer): based on: You are not allowed to view links. Register or Login to view.
- lct (linear color transfer): Matches the color distribution of the target image to that of the source image using a linear transform.
- mkl (Monge-Kantorovitch linear): based on: You are not allowed to view links. Register or Login to view.
- idt (Iterative Distribution Transfer): based on: You are not allowed to view links. Register or Login to view.
- sot (sliced optimal transfer): based on: You are not allowed to view links. Register or Login to view.

Enable gradient clipping ( y/n ?:help ) : This feature is implemented to prevent so called model collapsing/corruption which may occur when using various features of DFL 2.0. It has small performance impact so if you really don't want to use it you must enable auto backups as a collapsed model cannot recover and must be scraped and training must be started all over. Default value is n (disabled) but since the performance impact is so low and it can save you a lot of time by preventing model collapse I recommend enabling it always on all models.

Enable pretraining mode ( y/n ?:help ) : Enables pretraining process that uses a dataset of random peoples faces to initially train your model, after training it to around 200k-400k iterations such model can be then resused when starting training with proper data_src and data_dst you want to train, it saves time because you don't have to start training all over from 0 every time (the model will "know" how faces should look like and thus speed up the initial training stage) and it's recommended to either pretrain a model using this feature or by grabbing a pretrained model from our forum:
You are not allowed to view links. Register or Login to view.
Default value is n (disabled).
NOTE: The pretrain option can be enabled at any time but it's recommended to pretrain a model only once at the start (to around 200-400k iterations).
NOTE 2: You can also pretrain with your own custom faceset, all you need to do is create one (can be either data_src or data_dst) and then use 4.2) data_src (or dst) util faceset pack .bat file to pack into into one file, then rename it to faceset.pak and replace (backup old one) the file inside the "...\_internal\pretrain_CelebA" folder.

You can also just train a model on random faces in both data_src and data_dst but this method can cause morphing and as a result once you use a model prepared in such a way for a long time after starting training on proper datasets you trained faces may be morphing to old learned data and as result look less like SRC and more like faces it was trained on before or DST.

To use shared pretrained model simply download it and put all the files directly into your model folder, start training, press any key within 2 seconds after selecting model for training (if you have more in the folder) and device to train with (GPU/CPU) to override model settings and make sure the pretrain option is disabled so that you start proper training, if you leave pretrain options enabled the model will carry on with pretraining. Note that the model will revert iteration count to 0, that's normal behavior for pretrained model, unlike a model that was just trained on random faces without the use of pretrain function.

Shared models: You are not allowed to view links. Register or Login to view.

7. Merging:

After you're done training your model it's time to merge learned face over original frames to form final video (convert).

For that we have 2 converters corresponding to 2 available models:

7) merge SAEHD
7) merge Quick96

Upon selecting any of those a command line window will appear with several prompts.

1st one will ask you if you want to use an interactive converter, default value is y (enabled) and it's recommended to use it over the regular one because it has all the features and also an interactive preview where you see the effects of all changes you make when changing various options and enabling/disabling various features
Use interactive merger? ( y/n ) :

2nd one will ask you which model you want to use:
Choose one of saved models, or enter a name to create a new model.
[r] : rename
[d] : delete
[0] : df160 - latest
:

3rd one will ask you which GPU/GPUs or CPU you want to use for the merging (conversion) process:
Choose one or several GPU idxs (separated by comma).
[CPU] : CPU
[0] : GeForce GTX 1060 6GB
[0] Which GPU indexes to choose? :

Pressing enter will use default value (0).

After that's done you will see a command line window with current settings as well as preview window which shows all the controls needed to operate the interactive converter/merger.

Here is a quick look at both the command line window and converter preview window:
[Image: You are not allowed to view links. Register or Login to view.]

Converter features many options that you can use to change the mask type, it's size, feathering/blur, you can add additional color transfer and sharpen/enhance final trained face even further.

Here is the list of all merger/converter features explained:

1. Main overlay modes:
- original: displays original frame without swapped face
- overlay: simple overlays learned face over the frame
- hist-match: overlays the learned face and tires to match it based on histogram (has 2 modes: normal and masked hist match, toggable with Z button)
- seamless: uses opencv poisson seamless clone function to blend new learned face over the head in the original frame
- seamless hist match: combines both hist-match and seamless.
- raw-rgb: overlays raw learned face without any masking

NOTE: Seamless modes can cause flickering, it's recommended to use overlay.

2. Hist match threshold: controls strength of the histogram matching in hist-match and seamless hist-match overlay mode.
Q - increases value
A - decreases value


3. Erode mask: controls the size of a mask.
W - increases mask erosion (smaller mask)
S - decreases mask erosion (bigger mask)


4. Blur mask: blurs/feathers the edge of the mask for smoother transition
E - increases blur
D - decreases blur


5. Motion blur: upon entering initial parameters (interactive converter, model, GPU/CPU) merger/converter loads all frames and data_dst aligned data, while it's doing it, it calculates motion vectors that are being used to create effect of motion blur which this setting controls, it let's you add it in places where face moves around but high values may blur the face even with small movement. The option only works if on set of faces is present in the "data_dst/aligned" folder - if during cleanup you had some faces with _1 prefixes (even if only faces of one person are present) the effect won't work, same goes if there is a mirror that reflects target persons face, in such case you cannot use motion blur and the only way to add it is to train each set of faces separately.
R - increases motion blur
F - decreases motion blur


6. Super resolution: uses similar algorithm as data_src dataset/faceset enhancer, it can add some more definitions to areas such as teeth, eyes and enhance detail/texture of the learned face.
T - increases the enhancement effect
G - decreases the enhancement effect


7. Blur/sharpen: blurs or sharpens the learned face using box or gaussian method.
Y - sharpens the face
H - blurs the face
N - box/gaussian mode switch


8. Face scale: scales learned face to be larger or smaller.
U - scales learned face down
J - scales learned face up

9. Mask modes: there are 6 masking modes:

dst: uses masks derived from the shape of the landmarks generated during data_dst faceset/dataset extraction.
learned mask: uses masks learned during training as described in step 6. If learned mask was disabled it will use dst mask instead.
fan-prd: 1st FANseg masking method, it predicts the mask shape during merging and takes obstructions (hands, glasses, other objects covering face) into account to masks them out.
fan-dst: 2nd FANseg masking method, it predicts the mask shape during merging by taking dst mask shape into account + obstructions.
fan-prd + fan-dst: 3rd FANseg masking method, combines fan-prd and fan-dst method.
fan-prd + fan-dst + learned: combines fan-prd, fan-dst and learned mask method.

FAN-X masking options are now longer available and were replaced by XSeg model that doesn't come pretrained with DFL, you need to train your own model by first masking several DST (for XSeg-dst) or SRC (for XSeg-prd) faces and then train it, more on it in this guide:

You are not allowed to view links. Register or Login to view.
You can also mask it manually:
You are not allowed to view links. Register or Login to view.

10. Color transfer modes: similar to color transfer during training, you can use this feature to better match skin color of the learned face to the original frame for more seamless and realistic face swap. There are 8 different modes:

RCT
LCT
MKL
MKL-M
IDT
IDT-M
SOT - M
MIX-M


examples coming soon.

11. Image degrade modes: there are 3 settings that you can use to affect the look of the original frame (without affecting the swapped face):
Denoise - denoises image making it slightly blurry (I - increases effect, K - decrease effect)
Bicubic - blurs the image using bicubic method (O - increases effect, L - decrease effect)
Color - decreases color bit depth (P - increases effect, ; - decrease effect)

Additional controls:

TAB button - switch between main preview window and help screen.
Bear in mind you can only change parameters in the main preview window, pressing any other buttons on the help screen won't change them.
-/_ and =/+ buttons are used to scale the preview window.
Use caps lock to change the increment from 1 to 10 (affects all numerical values).

To save/override settings for all next frames from current one press shift + / key.
To save/override settings for all previous frames from current one press shift + M key.
To start merging of all frames press shift + > key.
To go back to the 1st frame press shift + < key.
To only convert next frame press > key.
To go back 1 frame press < key.

8. Conversion of frames back into video:

After you merged/convert all the faces and you will have a folder named "merged" inside your "data_dst" folder containing all frames that makeup the video.
Last step is to convert them back into video and combine with original audio track from data_dst.mp4 file.

To do so you will use one of 4 provided .bat files that will use FFMPEG to combine all the frames into a video in one of the following formats - avi, mp4, loseless mp4 or loseless mov:
- 8) merged to avi
- 8) merged to mov lossless
- 8) merged to mp4 lossless
- 8) merged to mp4

And that's it! After you've done all these steps you should have a file called result.xxx (avi/mp4/mov) which is your deepfake video.

tutsmybarreh's Forum Info
Joined:
03-17-2019
Last Visit:
(Hidden)
Total Posts:
1,120 (2.34 posts per day | 6.7 percent of total posts) Find All Posts
Total Threads:
62 (0.13 threads per day | 1.87 percent of total threads) Find All Threads
Time Spent Online:
(Hidden)
Thanks/Likes:
Given: 26 | Recieved: 335
Members Referred:
0
tutsmybarreh's Contact Details
Additional Info About tutsmybarreh
Sex:
Undisclosed
tutsmybarreh's Signature
If I helped you in any way or you enjoy my deepfakes, please consider a small donation.
Bitcoin: 1C3dq9zF2DhXKeu969EYmP9UTvHobKKNKF
Want to request a paid deepfake or have any questions reagarding the forums or deepfake creation using DeepFaceLab? Write me a message.
TMB-DF on the main website - You are not allowed to view links. Register or Login to view.