[Script] Copy every Nth face to subfolder - Lightning fast facesets

Want to know about the Faceswap's Face Extraction process? Got tips, ideas or just want to learn about how it all works? Then this is the place for you

Forum rules

Read the FAQs and search the forum before posting a new topic.

This forum is for discussing tips and understanding the process involved for Extracting and preparing face sets for training a model in Faceswap.

If you have found a bug are having issues with the Extraction process not working, then you should post in the Extract Support forum.

Please mark any answers that fixed your problems so others can find the solutions.

Post Reply
User avatar
Posts: 11
Joined: Sun Jul 14, 2019 11:39 pm
Has thanked: 2 times
Been thanked: 2 times

[Script] Copy every Nth face to subfolder - Lightning fast facesets

Post by Surrogator »

The following Windows batch script will create a subdirectory named subset in the working directory where it's called, and then copy every Nth file from the working directory into the subdirectory.

This is useful if you want to create a faceset from an extraction with a low Extract Every N setting (usually EEN=1 if you're using that video for conversion later). Instead of re-extracting those faces with FaceSwap at a higher EEN, you can use the following (Windows) script to copy 1 every N files into a subdirectory.

In the example below, the script lives here:

Code: Select all


When you call the script, you must provide a number for N. For example:

Code: Select all

.\every 10
every_bat.png (123.08 KiB) Viewed 15513 times

Code: Select all

@ECHO off

SETLOCAL EnableDelayedExpansion
SET /A every = %1
SET /A index = 0
SET /A files = 0
SET /A count = 0

MKDIR subset

ECHO Making a copy every %every% files...

FOR %%G IN (*) DO (
    SET /A files += 1
    SET /A index += 1
    IF !index! EQU %every% (
        @COPY "%%G" .\subset 1>NUL
        SET /A count += 1
        SET /A index = 0

ECHO Copied %count%/%files% files.



User avatar
Posts: 10
Joined: Sat Jan 04, 2020 6:30 pm
Has thanked: 6 times
Been thanked: 1 time

Re: [Script] Copy every Nth face to subfolder - Lightning fast facesets

Post by Now »

thanks, will give it go next time, had problems doing this is the past.. want to keep the number of frames to a min... currently on 10 k either side.

User avatar
Posts: 21
Joined: Wed Aug 19, 2020 3:17 pm
Has thanked: 2 times
Been thanked: 3 times

Re: [Script] Copy every Nth face to subfolder - Lightning fast facesets

Post by Korben »

I dont know if this should go here but I have a powershell script that allows to extract multiple videos at once.

Code: Select all

This script will extract the faces for all the files in a specified folder. 
For a folder with this content:

The final content of the foldre wouldc be:

conda activate "faceswap"
$everyN=1  #every nth frame
$minSize =1 #min face size
#Get all the files in a folder matching a filter.
$Files = Get-ChildItem -Path "D:\ExampleFolder\*.m*"

Write-Host "**********Found " $files.count " files***********"
$done= New-Object System.Collections.Generic.List[System.Object]
#loop through all the files and extract them if they dont already have a .fsa file
$files | foreach-object {     
    $outPut= $_.DirectoryName +"\"+$_.BaseName      
     if((Get-Item "$($outPut)_alignments.fsa" -ErrorAction SilentlyContinue)) {
        #do nothing faces already extracted.
        Write-Host "Already exists:" $_.FullName
    } else {
        Write-Host "EXTRACTING:" $_.Name   
        #Adjust this according to your settings.
        python.exe C:\<pathToYourFaceSwap>\faceswap.py extract -i "$($_.FullName)" -o "$($outPut)" -M unet-dfl -D s3fd -A fan -nm none -min $minSize -l 0.4 -een $everyN -sz 256 -si 0 -L INFO            
    } }

    Write-Host "WORK DONE:" 
    $done | foreach-object { 
        Write-Host $_



Post Reply