MrDeepFakes Forums
  • New and improved dark forum theme!
  • Guests can now comment on videos on the tube.
   
tutsmybarreh[GUIDE] - DeepFaceLab 2.0 EXPLAINED AND TUTORIALS (recommended)
#1
DeepFaceLab 2.0 Guide/Tutorial

[Image: eWsS3rBh.jpg]

GUIDE IS BEING WORKED ON. EXPECT UPDATES SOON.

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  pretrained models: 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 with zero dependencies for all windows versions.
  • Includes 2 models: SAEHD (4 architectures) and Quick 96.
  • Support for multi-GPU training.
  • Increased performance during faceset (dataset) extraction, training and merging thanks to better optimization (compared to DFL 1.0)
  • Faceset enhancer tool - for upscaling/enhancing detail of source faceset (dataset).
  • New GAN Power option - Generative Adversarial Network training, which enhances details of the face.
  • New 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 files for post process work in external video editing software with option to render it out as black and white video.
  • 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.
  • Facese (dataset) extraction with S3FD and/or manual extraction.
  • Training at any resolution in increments of 16. Possibility of training models at resolutions up to 256.
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:

The GitHub page of DFL 2.0 can be found here (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.
You are not allowed to view links. Register or Login to view.

NOTE FOR GOOGLE DRIVE: If you get info about download quota exceeded, right click -> add to my drive then in your drive make a copy of it (right click -> copy) and download that new copy.

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 you may consider trying out Google Cloud Computing service Google Colab and our DFL implementation on it: 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 dataset containing aligned face images (256x256) that are extracted from the target (destination) video data_dst.mp4 and they contain information about the shape of faces, their features (eyes,mouth,nose,eyebrows) and their position on the image, upon extraction/aligning process 2 folders are created within the "data_dst" folder:

"aligned" containing images of faces, 256x256 in size (with the alignment 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 dataset containing images of faces that are extracted either from data_src.mp4 file (that can be interview, movie, trailer, etc) or from images of your source - basically these are extracted faces of the person we want to put onto the body/head of the other person (onto the target/destination video).
By default upon extraction this folder only contains the "aligned" folder but "aligned_debug" folder can be also generated (you get to choose during extraction).

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 either "face extraction/alignment" 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 256x256 face images from the extracted frames located inside "data_src" folder.

There are 2 methods:
4) data_src extract faces S3FD - automated extraction using S3FD algorithm.
4) data_src extract faces MANUAL  - manual extraction.
Available options are:
- 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] histogram similarity
[4] histogram dissimilarity
[5] brightness
[6] hue
[7] amount of black pixels
[8] original filename
[9] one face in image
[10] absolute pixel difference
[11] best faces

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 only 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 extract faces MANUAL RE-EXTRACT DELETED ALIGNED_DEBUG - this one is used to manually align/extract faces for frames that were deleted from "aligned_debug" folder (more on that in next step - Data_dst cleanup)
5) data_dst extract faces MANUAL - manual extraction.
5) data_dst extract faces S3FD + manual fix - automated extraction + manual one for frames where algorithm couldn't properly detect faces.
5) data_dst extract faces S3FD - automated extraction using S3FD algorithm.
Available options are:
- 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. 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.
5.3) data_dst mask editor - Allows you to manually edit mask of the data_dst aligned faces (so you can exclude parts of the face from showing up after merging/converting - where mask isn't present on the face, parts of the original face/frame will be visible) - optional feature.

Additionally mask editor has an option called Default eyebrows expand modifier - it let's you expand the mask above the eyebrows automatically without the need to manually edit mask for each face but it can cause issues on side profiles where the expansion will also cover background (recommended only for frontal angles and moderate side angles).

Example:

[Image: Tmy5tACh.jpg]

Results of edited mask training + merging (conversion with dst mask):

[Image: wNewLwjh.jpg]

It's a very tedious and time consuming process, instead if you want to get rid of obstructions in the deepfake you may want to give FANseg masks a go during merging/conversion. Instead you're more likely to just use FANseg conversions instead during merging process.

In the converter (or interactive converter which we recommend) you can select various mask modes like fan-prd, fan-dst, fan-prd * fan-dst, learned * fan-prd * fan-dst) which can be used to automatically mask out obstructions from faces (like glasses, hands that are covering/obstructing data_dst faces).

Here is an example of FANseg mode masking the hand:

[Image: M1gQaZfh.jpg]

Back to the cleanup, now that you know your tools here is an example of a complete workflow for cleaning up the data_dst dataset.

You start by sorting face 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.

You should first delete all false positives and unwanted faces. Now that you've done this you can either delete all incorrectly aligned faces of your target and move to the next step or you can cut them out and place into a separate folder, reason for this is that we next need to use 5.1) data_dst view aligned_debug results and find all frames where the landmarks are missing or are incorrectly placed on the faces of our target person, by setting those incorrectly aligned faces aside we can do few things with them that will let just copy them to the "aligned_debug" folder, replace those frames with them and while they are still highlighted in windows explorer hit delete to remove them, there will still be some that we will have to locate manually (such as all faces that weren't detected at all) but doing it this way can save you a lot of time, especially if there are a lot of incorrectly aligned faces in a long clip where they usually will be somewhere in the middle among correctly aligned ones and it might be hard to notice them. If you want to know how to do it here is the TIP #11 from my FAQ: You are not allowed to view links. Register or Login to view.

- sort your data_dst by any method (histogram, blur, yaw, etc) to find bad frames
- then copy them to a "new folder"
- rename original "aligned" to something else (like "aligned_1") so you can rename the "new folder" with bad faces to "aligned"
- then use 5.3.other) data_dst util recover original filename,
- after it finishes go to the "aligned" folder where you will have all the bad faces you found with original name and some prefix like _0 / _1
- hold shift while right clicking, open powershell and use this command:
get-childitem *.jpg | foreach {rename-item $_ $_.name.replace("_0","")}

- if you have more files with different prefixes, just run the command again by changing _0 to any other prefix you may have like _1:
get-childitem *.jpg | foreach {rename-item $_ $_.name.replace("_1","")}

- this way you can just copy those bad aligned frames into "aligned_debug", then you just click replace and then delete them while they are highlighted (useful if you happen to have lots of bad alignments)
- at the end delete the bad frames folder "aligned" and rename "aligned1" back to the original name.


No matter if you used my technique or found them all manually, you should now run 5.2) data_dst util recover original filename to recover original names/orders of the face images and then run 5) data_dst extract faces MANUAL RE-EXTRACT DELETED ALIGNED_DEBUG to extract faces you've just delete from "aligned_debug". After that's done you have your data_dst dataset cleaned up, with all faces correctly extracted (including partially visible one) and ready to train.

More detailed info is in the FAQ (which you should definitely read, has tons of common questions, bug fixes, tips, etc):
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.

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 256x256 pixels
- half face, mid-half face and full face mode
- 4 architectures: DF, LIAE, DFHD, LIAEHD
- 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.

After you've checked other peoples settings and decided whether you preffer fast training or you want to wait and run a heavier model 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, you already know what are the features, now here is a more detailed explanation of them in order they are presented to the user upon starting of the training:

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.
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.

Resolution ( 64-256 ?: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 256x256.

Face type ( h/mf/f ?:help ) : this option let's you set the area of the face you want to train, there are 3 options - half face, mid-half face and full face.
Full face trains on the whole face, half face only trains from mouth to eyebrows but can in some cases cut of top or bottom of the face and mid half face offers 30% bigger area trained than half face while also prevents most of the undesirable cut off of the face from occurring (but it can still happen). It's recommended to use full Face for most flexibility but half face and mid half face offer better details because at the same model resolution more pixels are being used to resolve detail of the face (because it's larger/more zoomed in).

[Image: UNDadcN.jpg]

AE architecture ( dfhd/liaehd/df/liae ?:help ) : This option let's you choose between 2 main learning architectures DF and LIAE as well as their HD version which offers more better quality at the cost of performance.

DF and LIAE architectures in DFL 2.0 SAEHD are based on the implementation of DF and LIAE models from DFL 1.0 SAE model.
Whereas DFHD and LIAEHD architectures in DFL 2.0 SAEHD are based on the implementation of DF and LIAE models from DFL 1.0 SAEHD model.
The essentail difference between HD and non-HD version of architectures is increased number of layers in the HD model 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.

Below is comparison between DFHD and LIAEHD models, trained on the same hardware, same resolution and other parameters using the same source and destination datasets.

[Image: CYDrKyg.jpg]

Thanks to @kkdlux for making the comparison: You are not allowed to view links. Register or Login to view.

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 mask when training with Learn mask enabled. Does not affect the quality of training.

The changes in performance when changing each setting (with exception of Decoder mask dimensions) can have varying effects on performance and it's not possible to measure effect of each one on performance and quality without extensive training. DFL creator @iperov set those at certain default values 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). Values should be changed by a factor of 2. 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 stable operation, keep them at default.

Learn mask ( y/n ?:help ) : Enabling this setting will cause your model to start learning the shapes of the faces to generate a mask that can be then used during merging. Masks are essential part of the deepfake process that let the merger place the new learne/deepfaked faces over original footage. By default merger uses dst mask that is generated during faces extraction/alignment process of your data_dst. If you don't enable this feature and select learned mask in the converter/during merging it will still use dst mask. Learned mask are generally better than default dst masks but using this feature has big impact on performance and VRAM usage so it's best to first train the model to a certain degree or fully and enable the mask only for a brief time (5-6k iterations) at the end or somewhere during training (can be enabled and disabled multiple times). Learned mask has no effect on the face quality, only on the mask. Learned mask can be used on it's own or in combination with FANseg mask modes. Default value is n (disabled).

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: YQHOuSR.jpg]

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 ?:help ) : This feature should be only enabled at the very end of training and should never be enabled if features like random warp of samples or flip faces randomly. Once your model is fairly well trained and sharp, you've disabled random warp of samples, it will let you get a bit more detail and sharpness at less iterations that it would normally take without it. Use with caution, enabling before the model is fully trained may cause it to never improve until you disable it and let the training go on with this features disabled. Default value is n (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).

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).

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: CYAJmJx.jpg][Image: quality_nowadays.jpg]
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).

Here is an example:
[Image: czScS9q.png]

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's recommended to use values up to 10 and decrease them during training down to 1 or even 0.1.
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.

Examples: (coming soon)

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 50k-100k 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 and it's recommended to either pretrain a model using this feature, by making your own data_src and data_dst with random faces of people 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 100-200k iterations).

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: BT6vAzW.png]

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.

The fastest masking method is dst but it cannot exclude obstructions, learned mask is better in terms of shapes but also cannot exclude them, fan-dst is a bit slower but can exclude obstructions and generally is good enough in most cases, fan-prd can be a bit unpredictable so it's not recommended, fan-dst+prd doesn't offer much better masks than dst and 6th option that combines fan-prd, fan-dst and learned mask is the best one but also the slowest and requires you to also train with learn mask on.

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/moc) which is your deepfake video.

------------------------------------------------------------------------------------------------------------------------------------------------------

Expect more updates to this guide in the future, for now that's it. If you have more questions that weren't covered in this guide or in any of the following threads:

DFL 1.0 Guide: You are not allowed to view links. Register or Login to view.
DFL 1.0/2.0 FAQ: You are not allowed to view links. Register or Login to view.
Celebrity/Source creation guide: You are not allowed to view links. Register or Login to view.
DFL 2.0 General overview thread: You are not allowed to view links. Register or Login to view.
Or in any other thread in the questions sections: You are not allowed to view links. Register or Login to view.

Feel free to post it here, any questions regarding common issues won't be answered, keep the thread clean and spam free, if you have a serious issue with the software, either create a new thread in the questions section or check the github for reported bugs/issues.

------------------------------------------------------------------------------------------------------------------------------------------------------

Current issues/bugs:

Most of the issues you can find on the github page: You are not allowed to view links. Register or Login to view.
Before you create a new thread about a issue/bug you have please check github page to see if it wasn't already reported and if it was fixed or there is a temporary solution.

Below I'm listing some bugs I and other users have run into:

Issue #1: SAEHD_default_options file located in the model folder doesn't refer to any model by name but contains information required for model to work, having two models with different dims settings (probably d_dims or d_mask_dims) will cause one of the models to get stuck on 2/5 during initialization.

Fix: always keep the SAEHD_default_options file together with all model files and only keep one model in the folder at a time, if you've deleted it by mistake create a new model with the same dims settings and only keep the SAEHD_default_options file, now you model should start

Issue #2: Using TrueFace training at any strength/power leads to bad results, example: You are not allowed to view links. Register or Login to view. also possibly this: You are not allowed to view links. Register or Login to view.

Fix: not known, issue not confirmed to be happening for all users (could be dependant on the model architecture or datasets used)

Have any more issues? Please post them in this thread.
Have a fix for any of those or figured it out? Please post that too!

------------------------------------------------------------------------------------------------------------------------------------------------------
CHANGELOG:
#2
Looking forward to this as I am lost AF! Sticking with 1.0 until I see 2.0 is more stable - and until I see some sort of best practices guide.
#3
Looking forward to you publishing the DF 2.0 guide !!

Without your guide 1.0, I would not have been able to make any video well, so thank you very much for doing this huge job of explaining how it works.

cheers
#4
(02-05-2020, 09:23 PM)xeliop Wrote: You are not allowed to view links. Register or Login to view.Looking forward to you publishing the DF 2.0 guide !!

Without your guide 1.0, I would not have been able to make any video well, so thank you very much for doing this huge job of explaining how it works.

cheers

DFL 1.0 guide was made mostly by @dpfks, I merely expanded some bits. FAQ is mine tho and you should check it out because it has some useful info (I'll be updating it with new stuff regarding 2.0 and all tips/answers regarding 1.0 will be tagged as such (or separated from other "general" tips that apply to both versions).

Once I test it all out I'll be making a guide in 2 parts - 1st one technical, explaining features, how they work and their effect on performance/quality and then 2nd one will be a "workflow" one (not sure if I'll make 2nd one yet and in what form, it might be an video tutorial for Patreon or something).
Raising money for a new GPU, if you enjoy my fakes or my work on forums consider donating via bitcoin, tokens or paypal/patreon, any amount helps!
Paypal/Patreon: You are not allowed to view links. Register or Login to view.
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.
#5
So as per the guide, Trueface, Learning rate dropout and GAN are all options that should only be applied towards the end of training, after the model has been trained well already. (Presumably, this applies to color transfer as well.) Any suggestions on the order in which these should be turned on? All together, or one at a time, or...
#6
(02-09-2020, 06:09 PM)aymanalz Wrote: You are not allowed to view links. Register or Login to view.So as per the guide, Trueface, Learning rate dropout and GAN are all options that should only be applied towards the end of training, after the model has been trained well already. (Presumably, this applies to color transfer as well.) Any suggestions on the order in which these should be turned on? All together, or one at a time, or...

Yes, no and depends but probably not at the same time.
Raising money for a new GPU, if you enjoy my fakes or my work on forums consider donating via bitcoin, tokens or paypal/patreon, any amount helps!
Paypal/Patreon: You are not allowed to view links. Register or Login to view.
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.
#7
Not sure if this is the right section to post this question in. In DFL 2.0 would anyone know how to convert with just and alpha channel (just the face) I know it was possible on the older versions but when I press 'V' in merger window the face gets checkerboard and the face gets soloed, but when I start the merger the files come through with the whole dst shot.

Would anyone know how i can achieve this, as i would not want to mask the face out in after effects to composite the shots?
#8
(02-09-2020, 09:17 PM)sjrizley95 Wrote: You are not allowed to view links. Register or Login to view.Not sure if this is the right section to post this question in. In DFL 2.0 would anyone know how to convert with just and alpha channel (just the face) I know it was possible on the older versions but when I press 'V' in merger window the face gets checkerboard and the face gets soloed, but when I start the merger the files come through with the whole dst shot.

Would anyone know how i can achieve this, as i would not want to mask the face out in after effects to composite the shots?

It's done in AfterEffects with the result.mp4 and result_mask.mp4

You are not allowed to view links. Register or Login to view.
#9
Can I have the Paypal of the author to send a Tip?
This tool is going to make me rich ;)
#10
(02-10-2020, 02:57 AM)ChristianIce Wrote: You are not allowed to view links. Register or Login to view.Can I have the Paypal of the author to send a Tip?
This tool is going to make me rich Wink

Donation links (paypal, yandex, btc) for author of DFL are on his github, scroll to the bottom: You are not allowed to view links. Register or Login to view.
And if you mean to the author of guide then I have a bitcoin address and no paypal but you can pledge to Patreon (with paypal) for 1 month (or more), links in my signature.
Raising money for a new GPU, if you enjoy my fakes or my work on forums consider donating via bitcoin, tokens or paypal/patreon, any amount helps!
Paypal/Patreon: You are not allowed to view links. Register or Login to view.
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.

Forum Jump:

Users browsing this thread: vafiev, 4 Guest(s)