Ask Your Question
0

OpenCV GPU without compiling ?

asked 2020-09-14 10:14:12 -0600

Kreace gravatar image

Hello, i'm pretty new to OpenCV. I would like to use my GPU (Nvidia Geforce GTX 970) to run a Yolov3 (and 4) Neural Net. It works without any problems with my CPU but as you may already understand it's slow.

So I changed theses two lines in my code : (python3 script)

    self.net.setPreferableBackend(cv2.dnn.DNN_BACKEND_CUDA)
    self.net.setPreferableTarget(cv2.dnn.DNN_TARGET_CUDA)

1- I understood that "setPreferableTarget" set the hardware on which the neural network will be compute but what does "setPreferableBackend" do ? What is a Backend?

I tried to run my script and I get this warning :

[ WARN:0] global ../modules/dnn/src/dnn.cpp (1363) setUpNet DNN module was not built with CUDA backend; switching to CPU

2- I understood that means that OpenCV wasn't install with CUDA support, am I right here?

3- Isn't there any other way to install OpenCV with CUDA other than compile it from source? I installed OpenCV with sudo apt-get install libopencv-dev so i thought that maybe there is a way to do it like that, i don't know.

Thank you for taking the time to read me and thank you in advance for answering me, tell me if you need some additional information.

edit retag flag offensive close merge delete

3 answers

Sort by ยป oldest newest most voted
1

answered 2020-09-15 18:57:23 -0600

heavyswat gravatar image

I just compiled OpenCV 4.5.0-pre with CUDA 11.0 on Ubuntu 20.04.

I have followed the official NVIDIA CUDA 11.0 with deb(local). It's so much easier than the run file. And please use GitHub openCV 4.5.0-pre so it is compatible with CUDA 11.0

edit flag offensive delete link more

Comments

I'm trying to get a clean new installation with Ubuntu 20.04 I have install CUDA 11.0 like you but I don't know how to download opencv 4.5.0-pre, I used :

git clone https://github.com/opencv/opencv.git

but the latest version i can find is 4.4.0

Kreace gravatar imageKreace ( 2020-09-17 07:48:54 -0600 )edit

It worked fine with opencv 4.4.0!

Kreace gravatar imageKreace ( 2020-09-18 03:03:46 -0600 )edit
1

answered 2020-09-15 03:16:48 -0600

Naser gravatar image

updated 2020-09-15 03:26:07 -0600

You need to build opencv with cuda support from source. You can find a nice solution in this link : build opencv with cuda support. I did it on my own PC without any problem.

edit flag offensive delete link more

Comments

Yes i found it too but it's for Ubuntu 18.04, I'm using Ubuntu 20.04 so i don't know if it's up to date

Kreace gravatar imageKreace ( 2020-09-15 03:43:57 -0600 )edit

I tested it on ubuntu 20.04 but there is some issues in cuda toolkit installing in ubuntu 20.04. So i couldn't configure it. But works fine in ubuntu 18.04. Why not use ubutnu 18.04 ?

Naser gravatar imageNaser ( 2020-09-15 06:30:30 -0600 )edit

I wanted to use ROS2 in my program so I decided to take the latest version (ROS2 Foxy Fitzroy) and they provide binary packages for Ubuntu 20.04 so i took it accordingly

Kreace gravatar imageKreace ( 2020-09-15 09:54:49 -0600 )edit
0

answered 2020-09-15 01:35:15 -0600

berak gravatar image

you won'r get any gpu support using prebuilt binaries from any package manager.

you'll have to install the CUDA sdk, get the opencv (github) and opencv_contrib src code, and build from that, using cmake

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2020-09-14 10:13:35 -0600

Seen: 8,921 times

Last updated: Sep 15 '20