neuralchen / SimSwap

An arbitrary face-swapping framework on images and videos with one single trained model!
Other
4.55k stars 895 forks source link

How do I use the GPU ? #257

Open AlonDan opened 2 years ago

AlonDan commented 2 years ago

Looking on my Task Manager (I'm on Windows 10) I see the CPU only used, GPU is on 0% I'm using the test_video_swap******.py files but it is not using the CPU

I've tried to add: --gpu_ids 0 to my batch files but I still see 0% on GPU. I also tried 1 (because I 'm not sure how it works) ...

What command should I add to my batch file to make it run with GPU? Thanks ahead!

Fibonacci134 commented 2 years ago

Hey, task manager does not adequately show information on compute GPU usage. Go to this directory : C:\Windows\System32\DriverStore\FileRepository\nvdm*\nvidia-smi.exe

Run the following commad

nvidia-smi

That should give you a more accurate reading. What is your iteration speed for a 1280X720 video?

AlonDan commented 2 years ago

Thanks, I've tried this directory you suggested, not having something like it but NVDIM with some id numbers, but none of these directories have nvidia-smi.exe

So I google how to find it (I use Windows 10 + Latest Nvidia Drivers) but only found that people mention it's on: C:\Program Files\NVIDIA Corporation\NVSMI in my case this directory is empty...

So I tried via NVIDIA Control Panel, under "Manage 3D settings" there is a way to display GPU activity icon on the notification area... but it only shows the apps, no percentage or any information about usage, it only shows what apps use my GPU.

Maybe I need some software to show me the usage of my GPU since I couldn't find nvidia-smi.exe at all.

-

QUESTIONS:

Anyway, is there a way I can PUSH the GPU (or even CPU) to use MORE than what it does now?

For example: Even when I use the default scripts as I mentioned originally, it uses around 14% - 20% of the CPU, and GPU is shown like 0% (on Task-Manager + my bios monitor system)

Still... can I make it use MORE of the CPU (or GPU) by adding some command on my batch files?

or some other file I need to edit?

If so, how can I do that, can somebody please explain?

Thanks ahead!

Fibonacci134 commented 2 years ago

Nvidia-smi is usually included with cuda-toolkit. Do you know your cuda driver version? You might have to run th command in PowerShell if you cant through cmd. Simswap is designed to run on gpu, if you didn't have one, it wouldn't be able to run without making some modifications, so believe me your gpu is being used. You can download the Nvidia software where it gives you a overlay of gpu usage and temperature, I believe its called GeForce Experience. Few questions before I can give you any helpful answers:

Also, what is your GPU/Cpu and what speeds are you getting currently on a clip that is 1280x720.

AlonDan commented 2 years ago

Thanks for the reply @Fibonacci134 ❤

I just checked it with the XBOX controller, it's have an overlay MODE when pressing the middle button. but it showed about 12% - 16% GPU usage when I converted a short1280x720 video as you mentioned for testing.

CPU usage was around 14%-21% only... isn't that weird? I got around 2-3 iterations (changes as it process), it is VERY slow...

Why it's limiting to ONLY to that low amount of usage, that's why I asked if I can somehow add some parameter to my batch files (which are pretty much copy past from the USSAGE instructions but with my folders) so the batch files just serve me as shortcuts, nothing more.

SPECS: GPU: GTX 980 4GB CPU: Intel i7 8770K 3.50 GHz RAM 32GB SSD OS: Windows 10

I did some tests to be sure it's not just happens on 1 case. I tested on 1 face first, then on multiple-faces... (even 4 at once)

So why do I get the same slow speed and usage of GPU / CPU?

It's like it won't go to... 90% - 100% even ?

While if I just render a video in most software's or render 3D my CPU + GPU goes to 90%-100% dancing between until the process is done.

I believe that the question in my case is: How can I PUSH it to give more CPU / GPU power then it is now?

Any ideas how I can tweak SimSwap to use more power?

Thanks ahead!

Fibonacci134 commented 2 years ago

No problem at all, im sure we can figure this out and help you optimize the environment 🙂. So, there are a few things that will help us narrow down the cause for the slow speed. For reference im using a Gtx 1650 mobile (on a laptop) with 4 Gb ram and 32 Gb ram on a linux os. Your gpu is definitely superior to mine; however i am getting around 7 it/s . We dont get full gpu usage because this model is not that particularly large, which is a good thing because then it would require a Gpu with more than 4Gb vram. We just need to figure out how to optimize the parameters to fit our usage. Okay lets narrow this down:

Please do the following once you have activated your environment: Type this line one at a time. -conda activate simswap -Import torch -torch.cuda.is_available() (This should return the statement as true) -torch.cuda.get_device_name() (This should output your gpu name)

Assuming all those steps, went as planned; lets do the following. If you have updated the driver on your GPU , chances are your Cuda version is 11.x which is not backwards compatible with cuda 10.2. if you installed pytorch according to the preparation provided by this repo, this might be causing issues for you. I will add more stuff from my computer, currently on my phone. Please type (while in environment) conda list This should give you the list of packages that you have installed, from this we can figure out where the compatibility issues are.

AlonDan commented 2 years ago

Thanks for taking the time to help, I appreciate it! Unfortunately, I'm not experienced with anaconda / code in general.

After I activated SimSwap, I'm stuck on the second line -Import torch I get this:

(base) Z:\SimSwap>conda activate simswap

(simswap) Z:\SimSwap>import torch
'import' is not recognized as an internal or external command,
operable program or batch file.

Not sure what I'm doing wrong, I also tried "conda import torch" but it's not a command (just trying to guess since I'm clueless).

Fibonacci134 commented 2 years ago

hey, before you import torch, type python and hit enter this will make your envionment act as a python script