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?
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.
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.
Related
To begin with, I am setting up environment for a machine-learning project. I plan to use tensorflow for the training, and opencv for data acquisition as well as pre-processing. In a prior project, I already have opencv installed in C++, but this time I want to keep all my code in python in order to make everything clean.
Is my plan achievable? Do I need to reconfigure or recompile the library? If so, is there a way to make the existing opencv library work with python?
If you have a better suggestion, you are welcome to post it below.
Info about my current system:
OSX 10.13.6
opencv 3.4.3 (installed with homebrew)
python 3.6.10
Compilation will be necessary only for the bindings. The python wrapper is generated from OpenCV's source. The stub code that gets generated has to be linked against Python and the OpenCV libraries.
The process starts with the Cmake file at modules/python/CMakeFiles.txt which shall define the list of modules that needs to be made available from Python. Next, the headers are grabbed and parsed from these by a python bindings generator script resident within OpenCV's source structure. The headers shall include function declarations etc which shall then be converted into wrapper functions by the same generator script.
You could try to modify the cmake to exclude/include any module that you do not want to compile and build the bindings. This will not recompile OpenCV
Please have a look at : OpenCV Python Bindings to understand in detail how the python bindings are being generated.
I am trying to install PyOpenPose on Windows 10, using Cmake GUI. It requires OpenCV so I downloaded the prebuild OpenCV for Windows. Then I cmake the repository, import the OpenCV directory, everything is ok, until it required Boost. I downloaded the latest Boost version 1.72.0 and copy it to C:\boost\boost_1_72_0, since the installation manual tells me to do that to get CMake to detect the Boost. But its detection was like this:
By reading it I guessed Cmake has detected the Boost but it could not detect the python, the missing is system python3 and the Boost 1.72.0 has been found. So I add a DPYTHON_EXECUTABLE and set its path to C:\Users\abc\AppData\Local\Programs\Python\Python38\python.exe but the problem still remains.
Those DBOOST_LIBRARYDIR and DBOOST_ROOT were added by me. Cmake exports the same errors even without those arguments.
So that I am stuck here.
Tensorflow recently released their new object detection api Is there any way to run this on windows? The directions apear to be for linux.
Yes, you can run the Tensorflow Object Detection API on Windows. Unfortunately it is a bit tricky and the official documentation does not reflect that appropriately. I used the following procedure:
Install Tensorflow natively on Windows with Anaconda + CUDA + cuDNN. Note that TF 1.5 is now built against CUDA 9.0, so make sure you download the appropriate versions.
Then you clone the repository and build the Protobuf files as described in the tutorial, but beware, there is a bug in Windows Protobuf 3.5, so make sure you use version 3.4.
cd [TF-models]\research
protoc.exe object_detection/protos/*.proto --python_out=.
Finally, you need to build and install the packages with
cd [TF-models]\research\slim
python setup.py install
cd [TF-models]\research
python setup.py install
If you get the exception error: could not create 'BUILD': Cannot create a file when that file already exists here, delete the BUILD file inside first, it will be re-created automatically
And make the built binaries available to your path python path, or simply copy the directories slim and object_detection to your [Anaconda3]/Lib/site-packages directory
To see everything put together, check out our Music Object Detector, which was trained on Windows and Linux.
We don't officially support the Tensorflow Object Detection API, but some external users have gotten it to work.
Our dependencies are pillow, lxml, jupyter, matplotlib and protobuf compiler. You can download a version of the protobuf compiler here. The remaining dependencies can be installed with pip.
As I said on the other post, you can use your local GPU in windows, as Tensorflow supports GPU on python.
And here is an example.
Unfortunately, Tensoflow does not support tensorflow-serving on windows. Also as you said Nvidia-Docker is not supported on windows. Bash on windows has no support for GPU either. So I think this is the only easy way to go for now.
The below tutorial was build specifically for using the Tensorflow Object Detection API on Windows. I've successfully used the below tutorial many times:
https://github.com/EdjeElectronics/TensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10
I am using python 3 on windows 7 and trying to get SCIP on it. Please see the image. I want to run a mixed integer program.
SCIP
Any further instructions will be helpful.
I downloaded SCIP 3.2.1 as seen in the image, but then I don't understand how to implement that command and where?
PySCIPOpt does not officially support Windows. There are step-by-step instructions though, in the GitHub issues.
In general, PySCIPOpt is an interface from Python to C that is built using Cython. You need to compile the interface linking to a C library of SCIP. You don't necessarily need to build this library yourself, you might want to use a precompiled one from http://scip.zib.de/#download instead.
You do need a C/C++ compiler in any case. BTW, "that command" is make which is a build tool for Unix that is used to compile code. It doesn'twork out of the box on Windows 7. You either need the Ubuntu Bash from Windows 10 or a Linux "emulator" like Cygwin.
I have a program that processes videos using foreground detection in OpenCV 2.4.9/python/on windows and packaged for a windows executable using py2exe. I recently updated opencv to opencv3 and repackaged my program. When i run on my computer (with opencv3 installed locally) everything goes fine.
However, when a user goes and downloads the program and runs it on another computer, they get the warning
Failed to load OpenCL runtime
This just seems to be just a warning, and i can detect no performance issues.
I have a couple options. I can just suppress this specific warning in a try statement, or i can somehow turn off the OpenCL on my computer for packaging the program. Suggestions on either strategy would be appreciated. Anything i am overlooking? To my understanding the OpenCL library is for acceleration using GPU.
Thanks,
the solution will be compiling the OpenCV libs without OpenCL and then link them to your application
I had encounter the same problem, here's my solution:
go to the Intel website and download the OpenCL library, then unzip it
run the install.sh file
If your install fails because of update-alternatives errors, maybe it's because you are using Ubuntu/Debian distro and the Intel install package has a wrong setting with it.
To solve this, xfanzone did a very good job on this. Take a look here.
download the patch zip file and patch your OpenCL package
install it again, now it should work fine
If you just don't need to use OpenCL, you can set the environment var as below:
export OPENCV_OPENCL_RUNTIME=999
Sometimes, if you want to turn on the opencl:
export OPENCV_OPENCL_RUNTIME=