[Outdated] 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
RakaMaru
Posts: 2
Joined: Tue Jun 16, 2020 12:14 am
Been thanked: 3 times

[Outdated] Training Using Google Colab

Post by RakaMaru »

[mod=torzdf]A new Notebook has been setup at the following location: viewtopic.php?f=23&t=1886 Please use that thread for further colab discussions.

I would like to thank the original Notebook author and contributors for their efforts so far.
[/mod]



Hello Faceswap Community.

I have spent weeks here learning and using tips to get good results in Faceswap. Thank you for this great community.

Lately I've been struggling with training times, so I decided to try to use the Google Colab, and the results are very good. Training for the same results, using the Colab has cut my training from weeks to just days.

In gratitude, I thought I would share my notebook which I'm currently using.

https://github.com/RakaMaru/Faceswap_Go ... lab_Master

Thank you


Tags:
User avatar
RakaMaru
Posts: 2
Joined: Tue Jun 16, 2020 12:14 am
Been thanked: 3 times

Re: Training Using Google Colab

Post by RakaMaru »

To keep the Colab from timing out, use this.

Google Colab Keep-Alive Script

Code: Select all

function ClickConnect(){
console.log(Date().toLocaleString()); 
document.querySelector("document-info").click() 
}setInterval(ClickConnect,60000)

In Chrome (Ctrl-Shift-i), then paste into the console.

User avatar
Bolos
Posts: 12
Joined: Thu Jun 25, 2020 1:53 pm
Has thanked: 11 times

Re: Training Using Google Colab

Post by Bolos »

Hi,

And before i get myself ambarrassed, i'd like to thank you, and everyone involved in this deepfake madness. :)

I've been trying to use your googlecolab workflow since i got to make faceswap work on my computer, but it's my working machine and it can't do both ^^. (by the way i'm on a mac, the trashcan one with a pair of amd D700 6gb)

So i think i got everything working from your google colab sheet (i pressed the make a copy, hope i don't messup up anything this way) but the last section "Run training" ( 06/30/2020 00:02:39 ERROR The Timelapse path '/content/face_a' does not contain any valid images).

I'm sorry to bother, since i'm a newborn noob, and despites my good will to try to read what is requested and/or hapening, i have to admit, i don't get much out of it.

I did make the same path in my google drive: My drive/colab_files/faceswap/faces --- with two zip files named face_a.zip
and face_c.zip (the names of the jpg files inside are differend tho img_21656.jpg and Poutin.13565.jpg)
They have been extracted with faceswap and are 256x256. (it's the same set i've worked fine on my desktop)

(EDIT) I read somewhere in the code that the image size is set on 128, so i changed mines to 128. But still having the same problem with : "The Timelapse path '/content/face_a' does not contain any valid images"

I did one thing i'm not confident at all just before this step, when the collab script asked to choose between
1 - AMD 2 - CPU 3 - NVIDA As i said i'm running a trashcan so i'm stock with amd but i still choosed nvidia thinking it's not my computer running... I made a mistake right?

If you had time to maybe kindly tell me where to go find some more informations on what have gone wrong at that step?
Meanwhile i'll go read more on the googlecollab notice ^^'

Thanks from advance.

M.

Last edited by Bolos on Tue Jun 30, 2020 3:17 pm, edited 1 time in total.
User avatar
bryanlyon
Site Admin
Posts: 793
Joined: Fri Jul 12, 2019 12:49 am
Answers: 44
Location: San Francisco
Has thanked: 4 times
Been thanked: 215 times
Contact:

Re: Training Using Google Colab

Post by bryanlyon »

It wont work with zipped images. The folder has to have the actual images extracted. That said, timelapse is an optional mode and you can just leave that blank and run without timelapse if you want.

User avatar
Bolos
Posts: 12
Joined: Thu Jun 25, 2020 1:53 pm
Has thanked: 11 times

Re: Training Using Google Colab

Post by Bolos »

Thank you for the answear. I might just pass for even dumber than i actually am, but i thought that in the collab sheet it is mentioned to put all images of face_a with the correct alignments.fsa fil and zip it... And of course same for face_b. I followed the nicely done collab sheetmentionned in the first post of RakaMaru.

There even is an action for unzipping the folders... But i might get something on the naming wrong. In the unzziping results there is this as a result on the section "Download training data": (it did that for all the images, that's just the last lines)

inflating: face_b/MACOSX/face_b/.face_b_00890.jpg
inflating: face_b/face_b/face_b_03341.jpg
inflating: face_b/
MACOSX/face_b/.face_b_03341.jpg

So i'm actually renaming the files at start so the name is only numbers... Probably loosing my time ^^' i mean learning :)

As for the timelaps, if i un derstood correctly, it's a sort of preview in or for g colab? The things is i didn't change anything on the code, but try hard to make my project fit it... And understand a few things along :)

Again thanks for your answear, feel a bit bad as if i was waisting poeple's time ^^

Cheers

M

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

Re: Training Using Google Colab

Post by Korben »

RakaMaru wrote: Tue Jun 23, 2020 8:47 pm

Hello Faceswap Community.

I have spent weeks here learning and using tips to get good results in Faceswap. Thank you for this great community.

Lately I've been struggling with training times, so I decided to try to use the Google Colab, and the results are very good. Training for the same results, using the Colab has cut my training from weeks to just days.

In gratitude, I thought I would share my notebook which I'm currently using.

https://github.com/RakaMaru/Faceswap_Go ... lab_Master

Thank you

This is friggin amazing and should be pinned or linked too in a guide. Got this working on the first try. :shock:
ps. I read this first so changed the clone version. viewtopic.php?f=6&t=864

User avatar
Bolos
Posts: 12
Joined: Thu Jun 25, 2020 1:53 pm
Has thanked: 11 times

Re: [Resource] Training Using Google Colab

Post by Bolos »

Hi to all,

I've tryed again a couple of times getting that colab sheet working...

So the old error message couldn't make the timelapse work, but simply deleting it made me go one step further (wich is great thanks a lot Bryanlyon)

But since i'm here like in the setting menu of a chinese phone i get this new error message that i can't resolve (nor really understand why) :

Setting Faceswap backend to NVIDIA
usage: faceswap.py train [-h] [-C CONFIGFILE] [-L {INFO,VERBOSE,DEBUG,TRACE}]
[-LF LOGFILE] -A INPUT_A [-ala ALIGNMENTS_PATH_A] -B
INPUT_B [-alb ALIGNMENTS_PATH_B] -m MODEL_DIR
[-t {dfaker,dfl-h128,dfl-sae,dlight,iae,lightweight,original,realface,unbalanced,villain}]
[-bs BATCH_SIZE] [-it ITERATIONS] [-g GPUS] [-msg]
[-o] [-pp] [-s SAVE_INTERVAL] [-ss SNAPSHOT_INTERVAL]
[-tia TIMELAPSE_INPUT_A] [-tib TIMELAPSE_INPUT_B]
[-to TIMELAPSE_OUTPUT] [-ps PREVIEW_SCALE] [-p] [-w]
[-ag] [-nl] [-wl] [-nf] [-nac]

(a bunch of text reminding the short cuts and what everything is for that i didn't past here)

faceswap.py train: error: argument -t/--trainer: invalid choice: '{trainer_type}' (choose from 'dfaker', 'dfl-h128', 'dfl-sae', 'dlight', 'iae', 'lightweight', 'original', 'realface', 'unbalanced', 'villain')

The thing is that i really don't touch to anything on the collab sheet, but did try to change the trainer type to différent models, none worked out.... Here is one try:

#set variables start
num_iterations = "100000"
save_every = "360"
save_model_every = "25000"
batch_num = "16"
num_gpus = "1"

trainer_type = "dlight"

model_dir = "/content/drive/My Drive/colab_files/faceswap/models/YourModelName"
alignments_file_a = "face_a/alignments.fsa"
alignments_file_b = "face_b/alignments.fsa"
timelapse_dir = "/content/drive/My Drive/colab_files/faceswap/output/timelapse"
#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}' \
-tia 'face_a' \
-tib 'face_b' \
-to '{timelapse_dir}'

If some one could kindly tell me wich stupid move i made (or didn't) and help me reach the last step....? I would more than appreciate. :)

User avatar
Korben
Posts: 26
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 »

did you make sure this points to your actual model folder, you normally should edit that line?
model_dir = "/content/drive/My Drive/colab_files/faceswap/models/YourModelName"

User avatar
Xanthos
Posts: 1
Joined: Sat Aug 22, 2020 10:34 pm

Re: [Resource] Training Using Google Colab

Post by Xanthos »

What command would you use to enable Warp to Landmarks? Thanks.

User avatar
torzdf
Posts: 2636
Joined: Fri Jul 12, 2019 12:53 am
Answers: 156
Has thanked: 128 times
Been thanked: 614 times

Re: [Resource] Training Using Google Colab

Post by torzdf »

-wl

My word is final

User avatar
Bolos
Posts: 12
Joined: Thu Jun 25, 2020 1:53 pm
Has thanked: 11 times

Re: [Resource] Training Using Google Colab

Post by Bolos »

Korben wrote: Sat Aug 29, 2020 2:21 pm

did you make sure this points to your actual model folder, you normally should edit that line?
model_dir = "/content/drive/My Drive/colab_files/faceswap/models/YourModelName"

First of all thank you very much for you answear! I should probably change my usename to dumb and dumber... I in fact didn't change that at all.

I just made another try, but i'm still missing some basic knowledge or commun sens. I'm really sorry to bother with these type of questions, but i'm trying to silply make it work. So i kept all the paraleters to what they look like at origine (on the colab sheet). I'm there for using the dlight model. Trying to be smart i changed that line in the code to this :

#set variables start
num_iterations = "50000"
save_every = "360"
save_model_every = "10000"
batch_num = "16"
num_gpus = "1"

trainer_type = 'dlight'

model_dir = "/content/drive/My Drive/colab_files/faceswap/models/dlight"
alignments_file_a = "face_a/alignments.fsa"
alignments_file_b = "face_b/alignments.fsa"

!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}' \
-tia 'face_a' \
-tib 'face_b' \
-to '{timelapse_dir}'

It didn't change the error message.

So i copied from my local drive all the files in a previous dlight model test. i have one folder dlight_logs (with one session in it), and four files as follow: dlight_state.json / dlight_state.jsaon.bk / dlight.h5 / dlight.h5.bk to the folder in my google drive /models... I guess it must be obvious, but it dodn't change anything. (i did mount again my drive after a few attempt ^^').

I really appologie since i have the feeling that i'm an old grandma complaning about the thing not working because i simply didn't push the on button...

If i understand correctly, i'm missing the model to point at...
model_dir = "/content/drive/My Drive/colab_files/faceswap/models/dlight"
What exactly am i supposed to point at? On my shitty mac the model is generated, so the folder is empty. Is it different in the collab sheet? Am i supposed to bring a model to it somehow?

Thank you for the good soul that has a few spare minutes to help me out, and i'll go read again the main explanations to try to understand a bit more...

Cheers to you all.

User avatar
PhiPham
Posts: 1
Joined: Fri Sep 04, 2020 9:44 am

Re: [Resource] Training Using Google Colab

Post by PhiPham »

Hi there. I really appreciated for your guide to use Colab to train model.

I got this problem, I really need your help

First, after I installed Tensorflow, it asked me to restart the the runtime. Thus, what should I do, proceed to run training or restart runtime. If I restart, does I need to run from the top to bottom again,

Secondly, I tried the option to restart the runtime but proceed straight to run training section. Then the colab infor that the Faceswap require python 3.7 or higher, whereas colab is only python 3.6. I looked up the forum for the ans and found that I need to cloned Faceswap version 1.0. I followed the guide, but when I proceed back to the training section again, this time it prompt me issue that this version of faceswap only support tensorflow 1.15. Then I successfully downgraded ts to 1.15. BUT, aftern run training again, it asked me that: "Keras requires TensorFlow 2.2 or higher."

So, what should I do know. Please help me guys

User avatar
Korben
Posts: 26
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 »

Bolos wrote: Mon Aug 31, 2020 2:46 pm
Korben wrote: Sat Aug 29, 2020 2:21 pm

did you make sure this points to your actual model folder, you normally should edit that line?
model_dir = "/content/drive/My Drive/colab_files/faceswap/models/YourModelName"

First of all thank you very much for you answear! I should probably change my usename to dumb and dumber... I in fact didn't change that at all.

I just made another try, but i'm still missing some basic knowledge or commun sens. I'm really sorry to bother with these type of questions, but i'm trying to silply make it work. So i kept all the paraleters to what they look like at origine (on the colab sheet). I'm there for using the dlight model. Trying to be smart i changed that line in the code to this :

#set variables start
num_iterations = "50000"
save_every = "360"
save_model_every = "10000"
batch_num = "16"
num_gpus = "1"

trainer_type = 'dlight'

model_dir = "/content/drive/My Drive/colab_files/faceswap/models/dlight"
alignments_file_a = "face_a/alignments.fsa"
alignments_file_b = "face_b/alignments.fsa"

!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}' \
-tia 'face_a' \
-tib 'face_b' \
-to '{timelapse_dir}'

It didn't change the error message.

So i copied from my local drive all the files in a previous dlight model test. i have one folder dlight_logs (with one session in it), and four files as follow: dlight_state.json / dlight_state.jsaon.bk / dlight.h5 / dlight.h5.bk to the folder in my google drive /models... I guess it must be obvious, but it dodn't change anything. (i did mount again my drive after a few attempt ^^').

I really appologie since i have the feeling that i'm an old grandma complaning about the thing not working because i simply didn't push the on button...

If i understand correctly, i'm missing the model to point at...
model_dir = "/content/drive/My Drive/colab_files/faceswap/models/dlight"
What exactly am i supposed to point at? On my shitty mac the model is generated, so the folder is empty. Is it different in the collab sheet? Am i supposed to bring a model to it somehow?

Thank you for the good soul that has a few spare minutes to help me out, and i'll go read again the main explanations to try to understand a bit more...

Cheers to you all.

So here is what hints I can give at this point.

Make sure the "grab the lastest Faceswap" step grabs version 1 instead of the latest (the message I linked in my first post).

Code: Select all

!git clone --single-branch --branch r1.0 https://github.com/deepfakes/faceswap.git

Fist do you see your faces being extracted correctly? Make sure they didn't get compressed in an extra folder.
They need to be extracted like this faces_a/all_your_faces_here
not faces_a/faces_folder/all_your_faces_here
the output of the operation looks like this

Code: Select all

  
inflating: face_b/06628_0.png
inflating: face_b/alignments.fsa

Second I would try with no starting model but let it make a new one.
Just make sure this folder is empty on your google drive.
My Drive/colab_files/faceswap/models/dlight

But if you want to use an existing model it needs to have been started with an NVIDIA gpu if you want to use the collab GPU.
Make sure you copy the model folder under
My Drive/colab_files/faceswap/models/
so it looks like this
My Drive/colab_files/faceswap/models/dlight/all_the_model_files_here

Last edited by Korben on Sun Sep 06, 2020 6:43 pm, edited 1 time in total.
User avatar
Korben
Posts: 26
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 »

PhiPham wrote: Fri Sep 04, 2020 10:14 am

Hi there. I really appreciated for your guide to use Colab to train model.

I got this problem, I really need your help

First, after I installed Tensorflow, it asked me to restart the the runtime. Thus, what should I do, proceed to run training or restart runtime. If I restart, does I need to run from the top to bottom again,

Secondly, I tried the option to restart the runtime but proceed straight to run training section. Then the colab infor that the Faceswap require python 3.7 or higher, whereas colab is only python 3.6. I looked up the forum for the ans and found that I need to cloned Faceswap version 1.0. I followed the guide, but when I proceed back to the training section again, this time it prompt me issue that this version of faceswap only support tensorflow 1.15. Then I successfully downgraded ts to 1.15. BUT, aftern run training again, it asked me that: "Keras requires TensorFlow 2.2 or higher."

So, what should I do know. Please help me guys

Yes normally if you have to restart its because they gave your resources to someone else. This is why the model is saved to your google drive.

User avatar
Bolos
Posts: 12
Joined: Thu Jun 25, 2020 1:53 pm
Has thanked: 11 times

Re: [Resource] Training Using Google Colab

Post by Bolos »

Hi Korben, and thank you sooo much for taking the time to answear my problems :)

I've been taken on other projects, so haven't yet had the time to try all the procedur from scratch.

But for a quick response, in my last try (before i asked for some help ^^) i did take in count the change to the older version of facesawap as it had been explained elswere (can't remember but it might even be by you).

For the model part, the folder was empty, i did try to put a model in there once, but all my attempts were with a no pre model. I guessed that the model must stay on the same gpu family, happy to have no more doupts (i am stuck with amd at home, sh*t!).

for the image folder i'll have to verify, but at start i had them zipped as one g-collab demanded it (from my understanding) but have been trying without since bryanlyon told me. There for i don't do the unzipping step anymore (have tryed with, but it tells me unable to unzipped, since nothing is zipped).

I must be doing something wrong with the folder names or/and hierarchy. I'll triple check that.

I'd have one question, i'm on a mac, with amd gpus... I understood for g-collab it hasn't any incidence, i'm getting something wrong on that part? This feels like the dumbest question, but ah... i'm already past that point anyways ^^'

Again thanks, i'll take the time to go over carefully and will come back with a huge thanks, or new stupid questions...

User avatar
Bolos
Posts: 12
Joined: Thu Jun 25, 2020 1:53 pm
Has thanked: 11 times

Re: [Resource] Training Using Google Colab

Post by Bolos »

Hello to everyone. :)

I've been a bit busy so haven't had time to try out correctly all the process again. But had one though.

I uploaded my train.ini file as asked from my local disc in juin, i had installed an older version (don't know if it was the r.1 you mentionned in this : !git clone --single-branch --branch r1.0 https://github.com/deepfakes/faceswap.git) but i did the update in july. So the file on my google drive should be the one from past version, but i actually am not sure if it's the correct one. Could this make a problem?

Korben, i had a hard time installing it via terminal, and wouldn't want to mess it all up trying to install the old version to get the train.ini file i am supposed to feed colab. So can an incorrect train.ini ile mess it up? Is there a way to get a good train.ini file somewhere without downscaling faceswap on my comptuer?

I may have found a friend who understand a bit better coding and programing, so i'll try to go steal some time from him, and leave you guys a bit alone from my noob questions... ^^'

User avatar
hani
Posts: 1
Joined: Tue Sep 15, 2020 8:20 pm

Re: [Resource] Training Using Google Colab

Post by hani »

hi guys
unfortunately I cannot find the train.ini file. I cloned the r1.0 version, but there is no file under config directory. would you please someone help me out.
thanks in advance

User avatar
torzdf
Posts: 2636
Joined: Fri Jul 12, 2019 12:53 am
Answers: 156
Has thanked: 128 times
Been thanked: 614 times

Re: [Resource] Training Using Google Colab

Post by torzdf »

It only gets generated the first time you run faceswap

My word is final

User avatar
mshriver2
Posts: 1
Joined: Tue Sep 29, 2020 7:10 am

Error while training using google colab

Post by mshriver2 »

Hi I am trying to train a video using this google colab: https://colab.research.google.com/githu ... L4SaVqLmcP also I changed the second line to

Code: Select all

!git clone --single-branch --branch r1.0 https://github.com/deepfakes/faceswap.git

so that it could run on python v3.6 When I try to run the training I get this error: https://i.imgur.com/u2kS5Vx.png Any suggustions on how to fix this? I am a bit new to google colab, I have only used the faceswap gui in the past.

Thank you

User avatar
manintan
Posts: 4
Joined: Sat Nov 21, 2020 10:41 pm

Re: [Resource] Training Using Google Colab

Post by manintan »

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

Locked