neuralchen / SimSwap

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

onnxruntime GPU - error #94

Open instant-high opened 3 years ago

instant-high commented 3 years ago

After trying to 'upgrade' the old preparation to onnxruntime-gpu version SimSwap doesn't work anymore giving error onnxruntime not found (sorry, didn't copy the whole error message)

I only did this: pip install insightface==0.2.1 onnxruntime-gpu==1.2.0 moviepy

Fortunately I have external backups of my ENVS folder. So it was no big thing to get it back to work.

What can I do to make it work? (the gpu version)

mata3o commented 3 years ago

Im curious about this as well. All i did was the following to upgrade to GPU:

conda activate simswap pip install onnxruntime-gpu==1.2.0

It did download and install correctly and after i closed and re-opened anaconda. If i was suppose to install anything else i didnt think i was suppose to and when i ran my test picture and video i got these messages:

(simswap) C:\Users\user1\Desktop\Simswap\SimSwap-main>python test_video_swapsingle.py --isTrain false --use_mask --name people --Arc_path arcface_model/arcface_checkpoint.tar --pic_a_path ./demo_file/testpic.jpg --no_simswaplogo --video_path ./demo_file/testvid.mp4 --output_path ./output/testvid.mp4 --temp_path ./temp_results C:\Users\user1\MiniConda3\envs\simswap\lib\site-packages\onnxruntime\capi_pybind_state.py:13: UserWarning: Cannot load onnxruntime.capi. Error: 'DLL load failed: The specified module could not be found.' warnings.warn("Cannot load onnxruntime.capi. Error: '{0}'".format(str(e))) Traceback (most recent call last): File "C:\Users\user1\MiniConda3\envs\simswap\lib\site-packages\insightface__init.py", line 8, in import onnxruntime File "C:\Users\user1\MiniConda3\envs\simswap\lib\site-packages\onnxruntime\init__.py", line 12, in from onnxruntime.capi._pybind_state import get_all_providers, get_available_providers, get_device, RunOptions, SessionOptions, set_default_logger_severity, NodeArg, ModelMetadata, GraphOptimizationLevel, ExecutionMode ImportError: cannot import name 'get_all_providers'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "test_video_swapsingle.py", line 11, in from insightface_func.face_detect_crop_single import Face_detect_crop File "C:\Users\user1\Desktop\Simswap\SimSwap-main\insightface_func\face_detect_crop_single.py", line 8, in from insightface.model_zoo import model_zoo File "C:\Users\user1\MiniConda3\envs\simswap\lib\site-packages\insightface__init__.py", line 11, in "Unable to import dependency onnxruntime. " ImportError: Unable to import dependency onnxruntime.

Any help would be greatly appreciated , cheers!

ramnnv commented 3 years ago

I'm asking the same on another thread. I got the same error when i change onnxruntime from CPU to GPU.

NNNNAI commented 3 years ago

Yep, it will be difficult to install onnxruntime-gpu version actually, the specify version of onnxruntime maybe different depend on your machine and cuda version.Maybe you can check the list provided by onnx to find out the suitable version of onnx-gpu image

instant-high commented 3 years ago

Just tried pip install onnxruntime-gpu without explicit version number . That installed onnxruntime 1.81 Seems to work so far, gives one error message (I didn't copy that message)

My CUDA version 11.2.135

Unfortunately no change in inference time .... around 1.9 it/s for Video 1280x720

So I returned to previous installation.

Maybe I'll try a new separate SimSwap installation completly from the beginning, if that may change inference time??

EDIT: Using video 256x256 (like in first order model) and setting det-size to 256 speeds up to 7.5 it/s so I added a commandline parameter for various det-size values (depending on video resolution and size of the faces can set different det-size 256 / 320 / 480 or 640)

Polukeev commented 3 years ago

I had the same issue after installing onnxruntime 1.81(my videocard is nvidia gtx1070), and seems like i found out why it does not work properly. This version of onnxruntime requires proper version of cudatoolkit (11 or higher). I was trying to reinstall everything and install again and after all attempts i found out the solution which helped me.

I just updated pytorch to actual version with all cuda packages using: "pip3 install torch==1.9.0+cu111 torchvision==0.10.0+cu111 torchaudio===0.9.0 -f https://download.pytorch.org/whl/torch_stable.html"

and it started working just fine without any errors and speed of processing slightly increased.

I will try to downgrade pytorch to version 1.8.2 which is LTS version with cuda version 11.1 maybe it will increase speed even more "pip3 install torch==1.8.2+cu111 torchvision==0.9.2+cu111 torchaudio===0.8.2 -f https://download.pytorch.org/whl/lts/1.8/torch_lts.html"

mata3o commented 3 years ago

@Polukeev im a fellow 1070 user so ill have to do some toying with what you did this evening to check it out

@instant-high did changing to 256x256 degrade the outcome at all?

instant-high commented 3 years ago

@mata3o I mean if you have a small video containing only the face (maybe cut out before) or the face is small in the full frame decreased det-size mostly is working too. So of course don't resize the whole video to eg. 256

instant-high commented 3 years ago

I've tried on another computer, but not really satisfying result.

On the first one (GTX1050 / CUDA 11.2 / onnx-gpu 1.8.1) it get some error but it works, a bit slower than before, maybe fallback to cpu? On the second one (GTX1060 / CUDA ?? / onnx-gpu 1.8.1) it seems to work without error but also no improvement.

Errormessage: onnxgpuerror

Polukeev commented 3 years ago

@instant-high did you try my solution? I don't have this message anymore "Failed to load library". Run the command below and see will it help or no. "pip3 install torch==1.9.0+cu111 torchvision==0.10.0+cu111 torchaudio===0.9.0 -f https://download.pytorch.org/whl/torch_stable.html" As i said new version of cuda (11 and above) needs newer version of cudatoolkit.

instant-high commented 3 years ago

@Polukeev Never change a running system..... even worse than before. Nothing working, uninstalling onnx-gpu and installing onnx doesn't change the mess. Gladly external backup of environment folder solved this problem quickly.

Polukeev commented 3 years ago

@instant-high sorry about it, just wanted to help. Strange but it helped me to remove all types of errors but i am still not sure is onnx-gpu running or just simple onnx since there is no drastic change in processing speed (something around 0.5-0.6 it/s). "Never change a running system..... even worse than before" this is what i thought after installing onnxruntime-gpu for the first time. But without changes we will have the same results without improvements. I wish to see new version of this software where we will have possibility to have more source-face looking result.

instant-high commented 3 years ago

@Polukeev Everything is fine. After 30 years Windows and little bit programming I always use backups to avoid bigger trouble. Maybe Microsoft is invoved that's why it doesn' work as expected ;-)