[Resource] Training Using Google Colab

Want to use Faceswap in The Cloud? This is not directly supported by the Devs, but you may find community support here


Forum rules

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

NB: The Devs do not directly support using Cloud based services, but you can find community support here.

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

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

Re: [Resource] Training Using Google Colab

Post by Korben »

manintan wrote: Mon Nov 23, 2020 11:52 am

This doesnt even work, many of the steps are outdated or wrong.

If anyone has gotten this to work, please post a working version with all steps and folder naming etc...

This is a cleaned up version of what I am using.

Code: Select all

# -*- 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}' \

Tags:

User avatar
police.bike
Posts: 22
Joined: Tue Jun 30, 2020 3:37 pm
Has thanked: 7 times
Been thanked: 5 times

Re: [Resource] Training Using Google Colab

Post by police.bike »

Update - Feb 20, 2021

I was able to get both python 3.7 & 3.8 working on google collab and train using latest versions. Pretty amazing ones !

Just use this as block 1 before running any steps within the Collab notebook

Code: Select all

!sudo apt install python3.7
!update-alternatives --install /usr/local/bin/python3 python3 /usr/bin/python3.6 1
!update-alternatives --install /usr/local/bin/python3 python3 /usr/bin/python3.7 2
!python --version
!sudo apt update && upgrade
!sudo apt install python3-pip
!python -m pip install --upgrade pip
!pip --version
!python --version
!pip --version

Change 3.7 to 3.8 if you need it. This will reset python runtime to 3.7.5 and will get latest faceswap editions working.

Have fun !!!


User avatar
oNafodo
Posts: 2
Joined: Wed Feb 24, 2021 6:34 am

Re: [Resource] Training Using Google Colab

Post by oNafodo »

I put that all in a notebook and attempted to run it, all the steps worked except the final one of actually running the training.

This is the final cell I used

Code: Select all

"""# 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/Olya" 
alignments_file_a = "face_a/yt1s.fsa"
alignments_file_b = "face_b/Olya.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}' \

But when I run it, this is what I get back.

Code: Select all

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?


User avatar
hereforfun
Posts: 1
Joined: Wed Mar 03, 2021 6:11 pm

Re: [Resource] Training Using Google Colab

Post by hereforfun »

oNafodo wrote: Wed Feb 24, 2021 6:47 am

I put that all in a notebook and attempted to run it, all the steps worked except the final one of actually running the training.

But when I run it, this is what I get back.

Code: Select all

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.


User avatar
oNafodo
Posts: 2
Joined: Wed Feb 24, 2021 6:34 am

Re: [Resource] Training Using Google Colab

Post by oNafodo »

Thanks a million, that sorted it out.


User avatar
zachdidit
Posts: 1
Joined: Mon Mar 15, 2021 10:12 pm

Re: [Resource] Training Using Google Colab

Post by zachdidit »

I've got a Collab working with the latest version of Faceswap. Also added a cell to keep the runtime open through idle.

Be sure to change folders, filenames, timezone, etc

https://colab.research.google.com/drive ... sp=sharing


Post Reply