Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can opencv compiled with GPU support, fall back to CPU #5

Open
pks916 opened this issue Jan 20, 2025 · 10 comments
Open

can opencv compiled with GPU support, fall back to CPU #5

pks916 opened this issue Jan 20, 2025 · 10 comments

Comments

@pks916
Copy link

pks916 commented Jan 20, 2025

Is there any way to make opencv use cpu if gpu not detected.
right now i tried it and it gives the DLL no found error

ImportError: DLL load failed: The specified module could not be found.?

i do have the access to cudnn and cuda toolkit , appropriate version

@pks916 pks916 changed the title opencv GPU falls back to CPU can opencv compiled with GPU support, fall back to CPU Jan 20, 2025
@cudawarped
Copy link
Owner

I'm not sure I understand the question, if the dll isn't loading you cannot access either the CPU or GPU functions?

ImportError: DLL load failed: The specified module could not be found.?

@pks916 Do you know why you are getting this error? Is it because the cuDNN and CUDA toolkit shared libraries (dll's) are not present on your system and/or can't be found? How did you build the openCV python bindings?

Note: If you don't know how to check see https://cudawarped.github.io/opencv-experiments/nbs/ImportError_dll_load_failed_while_importing_cv2.html

@pks916
Copy link
Author

pks916 commented Jan 20, 2025

no gpu in the system
i put the dll files just for the path check in the config file so that it fails and switches to CPU
but instead of switching it exits and gives error mentioned above

@cudawarped
Copy link
Owner

The error does not relate to whether you have a GPU or not, it relates to whether the required shared libraries can be found. If you are seeing it check the link above to see which dll's are missing.

Are you using the pip install package and if not why not?

@pks916
Copy link
Author

pks916 commented Jan 20, 2025

i wanted to use opencv with gpu and use dnn package so i am using opencv-cuda wheels
and i wanted it to check if gpu present then use cuda as backend otherwise cpu backend
it should work, right?

@cudawarped
Copy link
Owner

Yes but when you are unable to import OpenCV, see the link above to find out why.

@pks916
Copy link
Author

pks916 commented Jan 20, 2025

so we can actually use model on cpu as well using the opencv with cuda, right?
when cv.cuda.getCudaEnabledDeviceCount() gives 0

@cudawarped
Copy link
Owner

You can run models on the CPU or GPU using the flags given in the documentation of the DNN module https://docs.opencv.org/4.x/d6/d0f/group__dnn.html.

@pks916
Copy link
Author

pks916 commented Jan 20, 2025

but it is working fine when gpu is present and detected, that is the main point.
my other pc does not have graphic card where i want to run these models, but it gives error instead of running models on CPU.

i have the models initialise as gpu backend if cv.cuda.getCudaEnabledDeviceCount() else run on opencv backend

@cudawarped
Copy link
Owner

my other pc does not have graphic card where i want to run these models, but it gives error instead of running models on CPU.

What is the error? If its

ImportError: DLL load failed: The specified module could not be found.?

this has nothing to do with the GPU being present it is because the shared libraries can't be found see the link in my first reply to address this error.

@pks916
Copy link
Author

pks916 commented Jan 20, 2025

ok i will see, but error is that only

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants