I'm trying to make OpenCV use GPU on google Colab but I can' find any tutorial what I fond is this tutorial
but I get stuck at step3 cuz this tutorial is not for colab
I'm trying to make OpenCV use GPU on google Colab but I can' find any tutorial what I fond is this tutorial
but I get stuck at step3 cuz this tutorial is not for colab
the default cv2 version installed on colab is 4.1.0 (very old !) and indeed, it has no CUDA support builtin. however, this is a google machine, it has all the tools, nooks & crannies to build your own ! latest cv2 ! with cuda ! (might take a good two hrs, though)
## 1st: switch to a gpu enabled runtime (from menu)
!git clone https://github.com/opencv/opencv
!git clone https://github.com/opencv/opencv_contrib
!mkdir /content/build
%cd /content/build
!cmake -DOPENCV_EXTRA_MODULES_PATH=/content/opencv_contrib/modules \
-DBUILD_SHARED_LIBS=OFF \
-DBUILD_TESTS=OFF \
-DBUILD_PERF_TESTS=OFF \
-DBUILD_EXAMPLES=OFF \
-DWITH_OPENEXR=OFF \
-DWITH_CUDA=ON \
-DWITH_CUBLAS=ON \
-DWITH_CUDNN=ON \
-DOPENCV_DNN_CUDA=ON \
/content/opencv
!make -j8
## the new cv2.so is now in /content/build/lib/python3/
## you are not allowed a normal install on colab, (not root)
## but you can copy it into your work folder and restart the runtime, so it forgets about the old version !
import cv2
cv2.__version__
!ls -l
## save for later use:
!cp /content/build/lib/python3/cv2.cpython-37m-x86_64-linux-gnu.so "/content/drive/My Drive/cv2_cuda"
## next time, load it into your work folder:
## dont forget to restart the runtime, so it forgets about the old version !
!cp "/content/drive/My Drive/cv2_cuda/cv2.cpython-37m-x86_64-linux-gnu.so" .