MrDeepFakes Forums

Some content may not be available to Guests. Consider registering an account to enjoy unrestricted access to guides, support and tools

  • We are looking for community members who are intested in helping out. See our HELP WANTED post.

[GUIDE] FaceSwap - How To Get Started: Part Two - Extraction and Training

Pocketspeed

DF Admirer
Verified Video Creator
wbrG0Y6.png


[font=Tahoma, sans-serif]FaceSwap Tutorial: Extraction and Training[/font]

[font=Tahoma, sans-serif]If you have not read Part One of this guide, please go back and do so now.[/font]

[font=Tahoma, sans-serif]This guide is based upon my personal understanding and workflow. There may be better or more efficient ways to accomplish the same tasks. This guide will cover only the essential basics of Faceswap usage. After you have used Faceswap a few times, you can experiment with more advanced settings and usage on your own. The purpose of this guide is simply to get you started.[/font]

[font=Tahoma, sans-serif]Step 1: EXTRACTION[/font]

[font=Tahoma, sans-serif]In order to create a DeepFake, we need two sets of data. Our data will be in the form of face images. We will have the face we want to replace. We will call this Data A. We will also have the face we want to put into our video. This is the face that is doing the replacing. We will call this Data B.[/font]

[font=Tahoma, sans-serif]Before we begin the extraction process, we need to create a basic folder structure. This will assist in keeping our project organized, and we will be less likely to accidentally delete data, or make mistakes. We do this by opening This PC (or My Computer if you are using an older version of Windows) and selecting the drive that we want to store our Faceswap data and images on. Let's assume we have 2 drives, the C drive (the primary drive that includes our OS), and an F drive (a secondary drive for additional storage). Note: you can do this on a single hard drive, if you don't have mutiple drives. The basic process is the same. The process is as follows:[/font]
  • [font=Tahoma, sans-serif]Open the drive where you want to store your Faceswap data and images. Your drive may be different the one in the image below.[/font]
  • [font=Tahoma, sans-serif]Create a new folder[/font]
  • [font=Tahoma, sans-serif]Name this folder “Faceswap_project”, or something similar. Whatever you want to call it is okay. Pro-tip: use an underscore instead of spaces in all of your folder creation. This can sometimes be important for Faceswap to find the folders later.[/font]
  • [font=Tahoma, sans-serif]Open your newly created folder.[/font]
  • [font=Tahoma, sans-serif]Now create several new folders inside your newly created folder. We will create new folders named: Video_A, Video_B, Img_A, Img_B, Align_for_Conversion_A, Align_for_Training_A, Align_B, Align_for_Training_B, Model, Sort_A, Sort_B, and Backups. The suffixes A and B tell us if Data A or Data B is contained within the folder.[/font]
  • [font=Tahoma, sans-serif]Don't worry too much about what all this means. You will begin to understand the reasons as you go through the process of DeepFake creation. After you have created your folder structure, it should be similar to the image below:[/font]
VgpNxUv.jpg


[font=Tahoma, sans-serif]The Backups folder will be for saving any files or folders that you might need later. It is a good idea to have backups of all your folders when using Faceswap. It is especially important to back up your Model folder after you have trained a model. We do these back ups as a fail safe measure in case something goes wrong or we make a mistake.[/font]

[font=Tahoma, sans-serif]Now we need some videos. We need a video for Data A, and a video for Data B. Remember that the Data A video will be the video we want to swap our face into. The Data B video will contain the face that will be doing the replacing. There are a number of ways to get your videos. These methods will not be covered in this guide.[/font]

[font=Tahoma, sans-serif]For ease of use, we need to break our extraction into two distinct categories. The first will be the face extractions that we will use for training the model. The second will be the face extractions that we will use during our conversion.[/font]

[font=Tahoma, sans-serif]We will begin by getting the face extractions for training . We will save this data for use later in the guide. In order to get our faces for our data, we first need to break our videos into single still-images, or “frames”. Open the Faceswap GUI as described in Part One of this guide. Near the top left corner of the GUI, we several tabs. Open the Effmpeg tab by clicking on it. Remember that you can hover your cursor over the different actions and selections, which will give you tooltips for more information about each setting. Let's get our frames for training:[/font]

MYw1Hna.jpg


  • [font=Tahoma, sans-serif]Set the action setting to extract.[/font]
  • [font=Tahoma, sans-serif]Set the input to the video you want your frames from. In this case, Video_A. Pro-tip: If you don't see your video available for selection, please ensure that “All Files” is selected in the bottom right of File Explorer.[/font]
  • [font=Tahoma, sans-serif]Set the output to the folder in which you will store your frames. In this case, Img_A.[/font]
  • [font=Tahoma, sans-serif]You can specifiy a reference video if you need to. If your input is a video, this is not necessary.[/font]
  • [font=Tahoma, sans-serif]Leave everything else on default, and click the Effmpeg button towards the bottom left of the GUI.[/font]
  • [font=Tahoma, sans-serif]Wait for the process to finish. This may take some time, and is dependent on the length of your video.[/font]
[font=Tahoma, sans-serif]Once this is done, we repeat this process for Data B. This time we select our input and output based on our Data B sources. So input should be Video_B, and output should be Img_B.[/font]

[font=Tahoma, sans-serif]We are done with getting our frames, and now we actually need to get the faces from them. Click the Extract tab near the top left of the GUI:[/font]

boPMwWY.jpg

  • [font=Tahoma, sans-serif]Select your input folder. In this case, Img_A. Pro-tip: There are two folder options for input. The first one to the left will extract faces directly from a video. The next one to the right will extract faces from frames. Choose the one best for your needs.[/font]
  • [font=Tahoma, sans-serif]Select your output. In this case, Align_for_Training_A.[/font]
  • [font=Tahoma, sans-serif]There are different options for the detector. Mtcnn is selected by default. We will use the default.[/font]
  • [font=Tahoma, sans-serif]There are different options for the aligner. Fan is selected by default. We will use the default.  [font=Tahoma, sans-serif][size=small]Update: The newer S3FD detector is now the preferred selection.[/font][/size][/font]
  • [font=Tahoma, sans-serif]You can set Rotate Images, if you need to.[/font]
  • [font=Tahoma, sans-serif]Use the slider to set Extract Every N to 10. We don't want to extract every face from every frame, as this can be hurtful to our data during training.[/font]
  • [font=Tahoma, sans-serif]Check the Multiprocess checkbox under options, if you want. There is also a checkbox for an Align Eyes option. Success with Align Eyes varies.[/font]
  • [font=Tahoma, sans-serif]Leave everything else on default.[/font]
  • [font=Tahoma, sans-serif]Click the Extract button towards the bottom left of the GUI. [/font]
  • [font=Tahoma, sans-serif]Wait for the process to finish. This may take some time.[/font]
[font=Tahoma, sans-serif]Now we have our aligned faces, which is the Data A we will need for training. Now repeat the process for Data B. Insure that you choose the correct folders for input and output. Detector and Aligner should be the same as what was used for Data A.[/font]

[font=Tahoma, sans-serif]Before we begin training, we need to “clean” our data for both A and B. We need to discard any data in our Align folders that are not faces, are too blurry, are too dark, have obscured faces, etc. We only want clear unobstructed faces, mostly frontal views as much as possible. A basic rule of thumb is a face in which both eyes and eyebrows are visible. You can use some profile faces, but this is generally not recommended and should be kept to a minimum number.[/font]

[font=Tahoma, sans-serif]We will have to delete our bad faces manually, and this can be quite tedious and time-consuming. Fortunately, Faceswap has a Sort tab which will help us through this part of the process:[/font]

dJ5PMuS.jpg


  • [font=Tahoma, sans-serif]Select the input to be Align_for_Training_A.[/font]
  • [font=Tahoma, sans-serif]Select the output to be Sort_A.[/font]
  • [font=Tahoma, sans-serif]Select Final Process to be “Folders”.[/font]
  • [font=Tahoma, sans-serif]Sort by and Group By should be left to “hist”.[/font]
  • [font=Tahoma, sans-serif]Click the Sort button near the bottom left of the GUI.[/font]
  • [font=Tahoma, sans-serif]Wait for the process to finish.[/font]
[font=Tahoma, sans-serif]Repeat the process for Align_B. Input should be Align_B. Output should be Sort_B.[/font]

[font=Tahoma, sans-serif]Open your Sort A folder that you created earlier. Move the faces that you want to keep back into the Align_for_Training_A folder. When finished, delete or discard images that are left over in the Sort A folder. Now repeat this process for Sort B. Once this is complete, we can begin training our model.[/font]

[font=Tahoma, sans-serif]Step 2: TRAINING[/font]

[font=Tahoma, sans-serif]Start by configuring training plugins. Go to the Edit tab in the top left of the GUI, and select configure train plugins:[/font]

y0aXQp7.jpg



[font=Tahoma, sans-serif]There are two more tabs for train plugins, Global and Model. Global plugins will apply to all models. You can hover your cursor for tooltips and information for each option. We will select only Dssim Mask Loss in this case. Be aware that different configurations can have different effects on your training, and some will effect the amount of VRAM required to train the model that you choose.[/font]

Addendum March 11 2019: A seventh model has been added. This is the "Lightweight" model. This is for GPUs with less than 4 Gb of VRAM. It can train with only 1.6 Gb of VRAM (compensating for Windows 10) with a Batch Size of 8. Results will be less than spectacular, and your mileage may vary.

[font=Tahoma, sans-serif]We will also look at the Model tab:[/font]

SNEdgdy.jpg



[font=Tahoma, sans-serif]As you can see by the tabs, there are currently six different models to choose from. These are Dfaker, Dfl H128, Iae, Original, Unbalanced, and Villain. Some models have Lowmem checkboxes, but not all do. If you are using less than 4 Gb of VRAM, you should select the Lowmem box. The coverage slider for each model will adjust how much of the Data B face will appear. Most of the time, coverage of 70 to 75 will yield good results, but if this is your first time trying Faceswap, you may wish to leave everything on default for now. NOTE: Different models will have different requirements which may supersede the basic requirements for Faceswap. For example, the Unbalanced model needs a 6 Gb VRAM card or better, and the Villain model absolutely must have no less than 8 Gb of VRAM (and that is not using the model fully. Full Villain model will need over 9 Gb of VRAM.)[/font]

[font=Tahoma, sans-serif]Select the Original model, check the box for Dssim Loss, set Mask Type to None, and Coverage to 70. Press the OK button in the bottom right.[/font]

[font=Tahoma, sans-serif]Once back to the main screen of the GUI, we select the Train tab:[/font]

6ElM6W0.jpg


  • [font=Tahoma, sans-serif]Set Input A to Align_for_Training_A[/font]
  • [font=Tahoma, sans-serif]Set Input B to Align_for_Training_B[/font]
  • [font=Tahoma, sans-serif]Set Model Dir to the Model folder you created earlier.[/font]
  • [font=Tahoma, sans-serif]Set Trainer to original[/font]
  • [font=Tahoma, sans-serif]Batch Size can be increased for higher VRAM cards. It can be decreased for lower VRAM cards. There are limits to how much you can gain from this. Batch sizes are always in powers of 2. We will use a Batch Size of 64. If you have a 4 Gb card, you may want to use a Batch Size of 32 or 16.[/font]
  • [font=Tahoma, sans-serif]Set Preview Scale to 50.[/font]
  • [font=Tahoma, sans-serif]Check the Preview checkbox towards the bottom of the GUI.[/font]
  • [font=Tahoma, sans-serif]Click the Train button towards the bottom left of the GUI.[/font]
[font=Tahoma, sans-serif]Training will begin momentarily, and you will get a pop-up preview window. Towards the bottom right of the GUI you will see Loss Values being calculated with every iteration. The training process will take a lot of time. How much time depends on your graphics card and the settings and plugins that you have chosen, your batch size, as well as the model type you have chosen. Generally 12 hours, or even more, will be needed. The Loss Values are less important than they used to be with the older python scripts, but you'll probably want Loss Values of around .02 (for both A and B) or less. What is more important is the preview window. When you are satisfied with the results in the Preview Window, then you can stop the training process. To stop the training process, make sure that the preview pop-up window is selected, then press Enter on your keyboard. Your model will be saved, and the process will finish. Pro-tip: If you want to resume training on a model, you can. Make sure that the Model Dir points to the folder in which you've stored your model. Set your inputs and outputs as before, and begin training again. It will pick up where it left off. Don't forget to check the Preview checkbox towards the bottom.[/font]

[font=Tahoma, sans-serif]Once you are satisfied with your trained model, and you have saved and finished the process, you are ready to begin swapping the faces.[/font]


[font=Tahoma, sans-serif]Part Three: Conversion and Frequently Asked Questions[/font]
 

Pitblack97

DF Vagrant
HI,
Im stuck please help =/ I got the frames from the Videos and now i need the Faces, but everytime i click on Exrtact this report shows up:

08/09/2019 23:42:06 CRITICAL An unexpected crash has occurred. Crash report written to 'A:\Installationen\FAKEAPP\faceswap\crash_report.2019.08.09.234206519164.log'. Please verify you are running the latest version of faceswap before reporting


HEY,
sorry i forgot to post the exact crash reort :
08/09/2019 23:42:03 Detector.run MainThread _base run ERROR Caught exception in child process: 9232: cudaGetDevice() failed. Status: CUDA driver version is insufficient for CUDA runtime version
 

Pocketspeed

DF Admirer
Verified Video Creator
Pitblack97 said:
HI,
Im stuck please help =/ I got the frames from the Videos and now i need the Faces, but everytime i click on Exrtact this report shows up:

08/09/2019 23:42:06 CRITICAL An unexpected crash has occurred. Crash report written to 'A:\Installationen\FAKEAPP\faceswap\crash_report.2019.08.09.234206519164.log'. Please verify you are running the latest version of faceswap before reporting


HEY,
sorry i forgot to post the exact crash reort :
08/09/2019 23:42:03 Detector.run    MainThread      _base           run                       ERROR    Caught exception in child process: 9232: cudaGetDevice() failed. Status: CUDA driver version is insufficient for CUDA runtime version



Need full system specs with the full crash report. The crash report is typically found in C drive > users > [your username] > faceswap > crash report.

Alternatively, if you haven't already, try updating to the latest commit.
 

obaskly

DF Vagrant
Hi
i used a batch size of 8 because i have a bad performances
yI9467B.jpg

zbcyeTw.jpg

after a 35h of training it looks like this
bKfHMoV.jpg

i stopped the training once because i got an error dwm.exe error and i retored it later
when the video is done it doesn't contain any picture just the audio , so i used a software called VidLab and i made a video from the previous merged frames , and it looks like that
[video=youtube]
any help would be appreciated
Thank you
 

Xentinel

DF Vagrant
Verified Video Creator
Hi, thank you for your time, this is really useful. I have been creating some videos with deepfacelab but I cannot get the quality that I want, I Just came here to give a try to FSwap.
 
Top