Installing Scrapy. I actually had a bit of a problem installing Scrapy on my OSX machine — no matter what I did, I simply could not get the dependencies installed properly (flashback to trying to install OpenCV for the first time as an undergrad in college). After a few hours of tinkering around without success, I simply gave up and switched over to my Ubuntu system where I used Python 2.7. The rest of the modules listed are part of your Python installation. Refer to “Configuring your Raspberry Pi for face recognition” to install the software. We then parse two command line arguments:--cascade: The path to OpenCV’s Haar cascade (included in the source code download for this post).
Alight, so you have the on your GPU-enabled system. Let’s get OpenCV installed with CUDA support as well. While OpenCV itself doesn’t play a critical role in deep learning, it is used by other deep learning libraries such as Caffe, specifically in “utility” programs (such as building a dataset of images). Simply put, having OpenCV installed makes it easier to write code to facilitate the procedure of pre-processing images prior to feeding them into deep neural networks.
Because of this, we should install OpenCV into the same environment as our deep learning libraries, to at the very least, make our lives easier. Furthermore, in a GPU-enabled CUDA environment, there are a number of compile-time optimizations we can make to OpenCV, allowing it to take advantage of the GPU for faster computation (but mainly for C applications, not so much for Python, at least at the present time). I’ll be making the assumption that you’ll be installing OpenCV into the same environment as — in this case, I’ll be continuing my example of using the Ubuntu 14.04 g2.2xlarge instance on Amazon EC2.
Truth be told, I’ve already covered installing OpenCV on Ubuntu in, but I’ll explain the process here as well. Overall, the instructions are near identical, but with a few important changes inside the cmake command, allowing us to compile OpenCV with CUDA support. By the time you finish reading this blog post, you’ll have OpenCV with CUDA support compiled and installed in your deep learning development environment. Installing OpenCV with CUDA support Before we can compile OpenCV with CUDA support, we first need to install some prerequisites. $ pip install numpy Note: Again, you’ll want to read the first half of to better understand Python virtual environments if this is your first time using them. I also explain them more thoroughly and how to properly use them in on this website. Now, let’s download and unpack OpenCV.
If you’re using the default Amazon EC2 g2.2xlarge instance, then I highly suggest that you download the OpenCV sources and do your compiling on / mnt. The default g2.2xlarge instance has only 8GB of space, which once you factor in the system files, NVIDIA drivers, etc., is not enough room to compile OpenCV from source. $ cd opencvcompile The above command will create a new directory named opencvcompile in the / mnt volume, followed by giving the ubuntu user permission to modify it at their will.
Note: The / mnt volume is what Amazon calls “ephemeral storage”. Any data put on this volume will be lost when your system is stopped/rebooted. You don’t want to use / mnt to store long-term data, but it’s perfectly fine to use / mnt to compile OpenCV. Once OpenCV is compiled, it will be installed to the system drive — your OpenCV installation will not disappear between reboots. For this tutorial, I’ll be using OpenCV 3.1. But you could also use OpenCV 2.4.X or OpenCV 3.0. Use the following commands to download the source.
D BUILDEXAMPLES = ON. To start, take note of the WITHCUDA = ON flag. Technically, this flag will be set to ON by default since CMake is smart enough to detect that the CUDA Toolkit is installed. But, just in case, we’ll manually set the variable to WITHCUDA = ON to ensure CUDA support is compiled. From there, we add in a few more optimizations, mainly around using, an implementation of the BLAS (Basic Linear Algebra Subprograms) library in the CUDA runtime. We also indicate that we want to utilize the “fast math” optimizations, a series of extremely fast mathematical routines that are optimized for speed (they are written in Assembly) — and essentially perform little-to-no error checking. Again, the FastMath libraries are geared towards pure speed and nothing else.
After running cmake, take a look at the “NVIDIA CUDA” section — it should look similar to mine, which I have included below. Rw - r - r - 1 root staff 2138812 Jun 2 14: 11 cv2.so Note: You’ll want to find and make note of where your cv2. So file is on your system! Whenever we create a virtual environment (which we’ll be doing lots of to explore various deep learning libraries), you’ll want to sym-link the cv2. So file into the site - packages directory of your Python virtual environment so you have access to OpenCV. The last step is to sym-link the cv2.
So file (our Python bindings) into the cv virtual environment. $ sudo rm - rf opencvcompile Again, I can’t stress this point enough — you need to get comfortable working with Python virtual environments, the site - packages directory, and how to use symbolic links. I recommend the following tutorials to help understand each of them:. Python Virtual Environments:. About site-packages:. Symbolic links: Summary In today’s blog post, I detailed how to install OpenCV into our deep learning environment with CUDA support.
While OpenCV itself isn’t directly used for deep learning, other deep learning libraries (for example, Caffe) indirectly use OpenCV. Furthermore, by installing OpenCV with CUDA support, we can take advantage of the GPU for further optimized operations (at least from within C applications — there isn’t much support for Python + OpenCV + GPU, yet). Next week, I’ll detail how to install the Keras Python package for deep learning and Convolutional Neural Networks — from there, the real fun will start! Its been a rough day with opencv cuda is installed and when i run nvcc -V it prints the cuda 7.5 that i am using. Then i tried to compile opencv with cuda by following this tutorial. I had no problem and no errors and followed all the steps, cmake, make -j4, and sudo make install.
All worked fine. But when i try to import cv2 it seems that its not installed. When i list the files that are in /usr/local/lib/python2.7/site-packages its zero no files are there.
So i ran this command to locate the cv2.so file and this was the results: naif@naif-Z170-D3H:$ sudo find / -name “.cv2.so.” sudo password for naif: /home/naif/opencvcompile/opencv-3.1.0/build/lib/cv2.so /home/naif/.virtualenvs/cv/lib/python2.7/site-packages/cv2.so naif@naif-Z170-D3H:$ what went wrong?? Any suggestions? I’m having some trouble compiling openCV with CUDA. I am on Ubuntu 17.10 with python 3.6.4, environment managed by anaconda. My CUDA version is 9.1 I followed your instructions, expecting some errors as I don’t have the same setup.
My cmake command looks like this cmake -D CMAKEBUILDTYPE=RELEASE -D CMAKEINSTALLPREFIX=/usr/local -D WITHCUDA=ON -D ENABLEFASTMATH=1 -D CUDAFASTMATH=1 -D WITHCUBLAS=1 -D INSTALLPYTHONEXAMPLES=ON -D INSTALLCEXAMPLES=OFF -D OPENCVEXTRAMODULESPATH=././opencvcontrib-3.1.0/modules -D CUDAGENERATION=”” -D CUDAARCHBIN=5.2 -D CUDANVCCFLAGS=”-ccbin gcc-6″ -D ENABLEPRECOMPILEDHEADERS=OFF. I manually added my cuda arch because I had some trouble with the autodetect parameter. I set the compiler to gcc-6 because I read cuda doesn’t support newer versions. Also, after wandering on loads of forums including one of your other tutorial, I read that enabling precompiled headers could leads to some problems so I deactivated it. My cmake doesnt show any error but I still cant compile opencv. Currently, the error is the following one, which doesn’t help me much /home/martin/opencv/opencv-3.1.0/modules/core/include/opencv2/core/cuda/vecmath.hpp(205): error: calling a constexpr host function(“abs”) from a device function(“abs”) is not allowed.
The experimental flag ‘–expt-relaxed-constexpr’ can be used to allow this. Any idea or advice taking in account my set up?