Page 1 of 1

GPU not being used if commands executed via command-line.

Posted: Thu Dec 26, 2019 11:08 pm
by Stump

Hey guys, thanks in advance for any guidance.

I've been using a custom batch file to execute my faceswap commands. I decided yesterday that I wanted to update to the latest faceswap.

After doing so, if I launch the Faceswap gui via Anaconda Navigator, everything works well and my GPU is utilized correctly. However, if I use the "generate" feature to print the command-line command, and then run that command from CMD, then Faceswap instead uses my CPU instead of GPU.

Does anyone have any advice as to how I can fix this?


Re: GPU not being used if commands executed via command-line.

Posted: Thu Dec 26, 2019 11:14 pm
by torzdf

Almost definitely you are not running the command from inside your Faceswap Virtual Environment


Re: GPU not being used if commands executed via command-line.

Posted: Thu Dec 26, 2019 11:18 pm
by Stump

That's what I am assuming as well. Is it possible to run these commands from CMD at all? I'd been calling all my commands through CMD on previous versions without issue prior to updating (this is when python.bat was being used on faceswap.py, rather than python.exe. Dunno if that helps as reference).

I am calling the python from within the environment (C:\Users\butts\Anaconda3\envs\faceswap\python.exe) and using it on the faceswap created by that environment (C:\Users\butts\faceswap\faceswap.py).

Any advice as to how to run this correctly from CMD would be greatly appreciated.


Re: GPU not being used if commands executed via command-line.

Posted: Fri Dec 27, 2019 12:22 am
by Stump

After some research, I regrettably found I probably needed to install faceswap outside of a venv in order to continue using it with my custom scripts.

Thanks for your help!


Re: GPU not being used if commands executed via command-line.

Posted: Fri Dec 27, 2019 2:22 am
by torzdf

You shouldn't need to install it outside of a venv....

If you installed with the installer, check the file faceswap\windows_launcher.bat (or similar). It contains the command that launches the GUI into the venv.


Re: GPU not being used if commands executed via command-line.

Posted: Fri Dec 27, 2019 2:54 am
by Stump

I'm afraid I see no such file anywhere. I need to run things outside of the GUI and call specific parts of Faceswap from the command line. From what I understand, that's not a practical thing to do if it's residing within a virtual environment.

For example, in my batch file I have something like:
set /p batchSize="Enter batch size: "

It needs to take the output (16 for example) and execute training using -bs !batchSize!

Anyway, this machine is dedicated to Faceswap, so I am fine with installing it out of a virtual environment for now. I know I am on my own since I am doing this in an unconventional way.

Thanks again!


Re: GPU not being used if commands executed via command-line.

Posted: Fri Dec 27, 2019 12:37 pm
by torzdf

It absolutely is a practical thing to do.

The problem that I suspect you're running into is that it isn't enough just to call the specific python.exe.

Conda also handles Cuda/cuDNN etc, so executing a Faceswap command outside of the environment means that it won't find Cuda, hence the CPU mode being activated.

The installer creates a file (on Windows) called faceswap_win_launcher.bat in the Faceswap folder (it is what the desktop shortcut links to, if you can't find it).

As an example. the contents of my bat file are:

Code: Select all

"C:\Users\Matt\Miniconda3\scripts\activate.bat" && conda activate "faceswap" && python "C:\Users\Matt\faceswap/faceswap.py" gui

The first 2 commands would be necessary for scripting in a Conda env from the cli.