2

I want to use opencv-python4.4 to do inference for YOLOv3. But it uses CPU by default. I have read this instruction here, saying the new version opencv4.2.0 has already supported GPU. But the instruction is only for Ubuntu but mine is Windows10.

I tried to Could you please walk me through how to pull this off in Wondows10, python? As I directly used it, the error occurred:

cv::dnn::dnn4_v20191202::Net::Impl::setUpNet DNN module was not built with CUDA backend; switching to CPU

It seems that I have to manually compile opencv but isn't it for Cpp? But I only want to implement it on python. Could anyone give me some instructions?

2 Answers 2

2

You will indeed need to build OpenCV yourself.

While you're using the Python bindings for OpenCV, the OpenCV library itself is written in C++ instead of Python. That also explains how OpenCV can use CUDA, another C++ library to access NVidia GPU's.

The instructions you linked are from a person not associated with OpenCV, who admits to an anti-Windows bias. That means those instructions are not useful to you.

These instructions do cover the Windows build.

Summary:

  • Use Visual Studio 2019 (Latest C++ compiler from Microsoft) and CMake
  • Download & install OpenCV
  • Download & install CUDA and cuDNN
  • Download & install Anaconda3 and use it as default Python
  • Set environment variables so CMake can find your installed libraries
  • Set the environment variables and options so CMake knows that you also want the Python bindings for OpenCV
  • Use CMake to create .sln file for Visual Studio
  • Open .sln in Visual Studio and build it.
  • This generates the cv2.cp37-win_amd64.pyd file you need.
Sign up to request clarification or add additional context in comments.

6 Comments

I've found the same article myself. But still, thanks a lot for your reply!
I followed the instructions to generate build files. But I couldn't find python binding file anywhere (python3 path has been included)... And specifically I don't understand "Make sure you build release, python bindings cannot by default be generated for a debug configuration". He said building Release, but then swap to Debug somehow... I don't know which one I should do.
@dexter2406: That comment refers back to the cmake command line. It means the arguments to cmake should include --config Release instead of --config Debug.
So do I still need to modify pyconfig.h before build? I just rebuilt it with set "buildType=Release" and modified pyconfig.h, but there's still no sign of python binding files.
You'd change pyconfig.h only when you're hacking on OpenCV itself and need to debug that. I don't think you'd want to do that. But that would only affect what the bindings bind to. Did you follow step 4, " Verify that the cmake output detailing the modules to be built includes python3" ?
|
0

I have figured it out... both

-DBUILD_opencv_python3=ON
-DBUILD_opencv_python2=OFF

must be specified, otherwise the to be built will not include any python module at all.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.