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

Installing and setting up FaceSwap


Forum rules

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

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

Locked
User avatar
Stump
Posts: 4
Joined: Thu Dec 26, 2019 10:00 pm
Has thanked: 1 time

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

Post 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?

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

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

Go to full post
User avatar
torzdf
Posts: 2670
Joined: Fri Jul 12, 2019 12:53 am
Answers: 159
Has thanked: 131 times
Been thanked: 625 times

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

Post by torzdf »

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

My word is final

User avatar
Stump
Posts: 4
Joined: Thu Dec 26, 2019 10:00 pm
Has thanked: 1 time

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

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

User avatar
Stump
Posts: 4
Joined: Thu Dec 26, 2019 10:00 pm
Has thanked: 1 time

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

Post 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!

User avatar
torzdf
Posts: 2670
Joined: Fri Jul 12, 2019 12:53 am
Answers: 159
Has thanked: 131 times
Been thanked: 625 times

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

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

My word is final

User avatar
Stump
Posts: 4
Joined: Thu Dec 26, 2019 10:00 pm
Has thanked: 1 time

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

Post 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!

User avatar
torzdf
Posts: 2670
Joined: Fri Jul 12, 2019 12:53 am
Answers: 159
Has thanked: 131 times
Been thanked: 625 times

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

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

My word is final

Locked