How to use OpenCV with GPU on Colab?

I’m trying to utilize GPU of Colab for quadratic optimization. I followed this link to install the CV2 but after installation completed I couldn’t find any

cv2.cpython-36m-x86_64-linux-gnu.so

file, so the cv2 version remained native. Is there any special thing I have to do after installation?

your link is unfortunately behind a paywall.

can you show us the cmake cmdline & (console) output ?

this worked ok for me, a few weeks ago

one of the problems on colab is, that you cannot install python modules persistantly, my current workaround:

  • after building, copy the cv2.xxxx.so to some external place (e.g. a google drive)
  • whenever you need it - restart the runtime (so it forgets about preinstalled cpu only 4.1.0)
  • copy your own cv2.so to your work folder
  • start your python code, and pray, it picks up the local version before the global, preinstalled one
1 Like

The latest cv2 version was installed successfully, however after this code block:

!cp -r /content/build/lib “/content/drive/My Drive/cv2_cuda”
!cp /content/build/lib/python3/cv2.cpython-36m-x86_64-linux-gnu.so “/content/drive/My Drive/cv2_cuda”
!cp -r /usr/include/opencv2 “/content/drive/My Drive/cv2_cuda”

the output is:

cp: cannot stat ‘/content/build/lib/python3/cv2.cpython-36m-x86_64-linux-gnu.so’: No such file or directory

Why it can’t find the cv2.xxxx.so?

hehe, ran into something similar this morning, – default python was changed recently to 3.7 on colab :wink:

You mean it is possible to utilize GPU on Colab only with the python 3.7? Or it is impossible at all?!))

no, i meant, you probably have to look for:

/content/build/lib/python3/cv2.cpython-37m-x86_64-linux-gnu.so

(36<–>37)

have a look at your cmake output again, and check python --version

1 Like