# -*- coding: utf-8 -*-
"""# Setup Faceswap"""
#@title Set Time Zone to eastern
!rm /etc/localtime
!ln -s /usr/share/zoneinfo/America/New_York /etc/localtime
!date
#above is for HST, you can find yours in
#/usr/share/zoneinfo
#@title Mount Google Drive
from google.colab import drive
drive.mount('/content/drive', force_remount=True)
#@title Download training data
!rm -r face_a
!rm -r face_b
#under the root folder of my google drive ("My Drive") I created a /colab_files/faceswap/faces
#folder that contains zipped face data. Important the zip does not contain folders only the
#faces and alignments files.
#this copies the zip files from your google drive to the workspace while renaming them to a generic name
!cp "/content/drive/My Drive/colab_files/faceswap/faces/face_a_SomeName.zip" "./face_a.zip"
!cp "/content/drive/My Drive/colab_files/faceswap/faces/face_b_SomeName.zip" "./face_b.zip"
#unzip them in folders
!unzip face_a.zip -d face_a
!unzip face_b.zip -d face_b
#delete the zip files
!rm face_a.zip
!rm face_b.zip
#@title Grab the V1 version of Faceswap
!git clone --single-branch --branch r1.0 https://github.com/deepfakes/faceswap.git
#@title Install Tensorflow
#ignore the errors it still works
!pip install -r faceswap/requirements_nvidia.txt
#@title Copy configuration files
#if you copied config files from your pc to your google drive and want to use them uncomment this section.
#!cp "/content/drive/My Drive/colab_files/faceswap/config/train.ini" faceswap/config/
#!cp "/content/drive/My Drive/colab_files/faceswap/config/.faceswap" faceswap/config/
#!ls -lA faceswap/config/
#!cat faceswap/config/train.ini
"""# Run Training"""
#set variables start, will varry according to your trainer type etc...
num_iterations = "3000000"
save_every = "300"
save_model_every = "15000"
batch_num = "48"
num_gpus = "1"
trainer_type = "dfl-h128"
model_dir = "/content/drive/My Drive/colab_files/faceswap/models/YourModelFolder"
alignments_file_a = "face_a/alignments.fsa"
alignments_file_b = "face_b/alignments.fsa"
#set variables end
!python3 faceswap/faceswap.py train \
-A 'face_a' -ala '{alignments_file_a}' \
-B 'face_b' -alb '{alignments_file_b}' \
-m '{model_dir}' \
-t '{trainer_type}' \
-bs '{batch_num}' \
-it '{num_iterations}' \
-g '{num_gpus}' \
-s '{save_every}' \
-ss '{save_model_every}' \
Setting Faceswap backend to NVIDIA
usage: faceswap.py [-h] {extract,train,convert,gui} ...
positional arguments:
{extract,train,convert,gui}
extract Extract the faces from pictures or a video
train Train a model for the two faces A and B
convert Convert source pictures or video to a new one with the
face swapped
gui Launch the Faceswap Graphical User Interface
optional arguments:
-h, --help show this help message and exit
faceswap.py: error: unrecognized arguments: 1
Is there something I am supposed to be changing that I didn't?
Setting Faceswap backend to NVIDIA
usage: faceswap.py [-h] {extract,train,convert,gui} ...
positional arguments:
{extract,train,convert,gui}
extract Extract the faces from pictures or a video
train Train a model for the two faces A and B
convert Convert source pictures or video to a new one with the
face swapped
gui Launch the Faceswap Graphical User Interface
optional arguments:
-h, --help show this help message and exit
faceswap.py: error: unrecognized arguments: 1
Had the same issue, just remove the line containing the -g flag.
Spent a couple days learning colab and using faceswap with it using the script in this post which saved a ton of time. I'm getting an error on training though which I can't seem to figure out. I have the alignment files in the face_a and b folders which are under /content but it doesn't seem to like the alignment arguments. Any ideas?
I did notices one thing wierd. i have about 7000 images in face_a and scrolling though the list I can't see the alignment file, you see a ... and no way to expand it. I tried to upload a copy of the alignment file and move it to the folder and it fails. My storage isn't full. If I can't see it perhaps neither can the scripts. Is there a limit on number of files in a folder?
Last edited by HoloByteus on Tue Apr 13, 2021 12:57 am, edited 1 time in total.
ERROR: albumentations 0.1.12 has requirement imgaug<0.2.7,>=0.2.5, but you'll have imgaug 0.2.9 which is incompatible.
WARNING: The following packages were previously imported in this runtime:
[psutil]
You must restart the runtime in order to use newly installed versions.
I get the same error message about albumentations but it doesn't seem to hurt anything so I just ignore it. You do have to press the button to restart the runtime though (or at least I always do it.)
One thing to note is that Colab comes with Tensorflow already installed and Google advises you not to install your own because theirs is optimized for their hardware. So you shouldn't install another if you can get away with it. However they currently use Tensorflow 2.4 and I use 2.2 locally, so I have to downgrade theirs or I can't use the models it produces.
About your previous question, training doesn't need alignment files anymore so you shouldn't set those options. The necessary data is stored right in the face set image files, provided that you have extracted them with a recent version of faceswap.
Thank you. I was thinking something with the colab required the alignment files but doh, yea I guess the notebook was made before that change so removed them from the training cell resolved that issue.
Figured out the psutil issue, I was running the GPU check (which includes a psutil install) before installing Tensorflow. Not doing that resolved it. Looks like Villian requires Tensorflow install and upon restort ... TRAINING NOW WORKS!
The master notebook needs a few updates. I also changed the Data transfer to point to the content directory and then just zip the extracted faces folders and have the unzip create the folders on colab. Bit easier zip process.
Good point, will make the change to data transfer.
What are you using to bypass the colab interactive timeout? I have the javascript to click the connect button but I'm not a fan of how that keeps opening the cpu/gpu graphs. I found some javascript to click the comments button instead but would like to click the favorite Star instead for minimal visual impact. I haven't tested it yet but was wondering if this would work guessing the star for favorites would be labeled star.
Yes, found that same thread and decided on the following since it has a method to enable/disable. Changed it to target the comments instead of connect and that seemed to work enough to pass the first level check for interactivity. Carried me all the way through the hours I had left of the 12hr timeout after jumping through all the hoops to get this running.