0

Is it possible (up today) to use OpenCV-Python with GPU? I'm trying to implement an opencv based script for image processing using a GPU on AWS Sagemaker, but there seems to be a problem on compatibility. I already checked some sources on this topic:

Use GPU with opencv-python

https://forum.opencv.org/t/can-i-use-opencv-python-with-gpu/8947/2

But they are a bit old, and would like to know if there is an update on this compatibility. From previous projects on Windows, I used this Torchvision adapted version cvtorchvision and it worked good, but now it's too old and has no maintenance.

EDIT: Adding used versions (using AWS Sagemaker and Jupyter Labs):

  • opencv-python-headless-4.11.0.86
  • Cuda compilation tools, release 12.6, V12.6.85 Build cuda_12.6.r12.6/compiler.35059454_0
  • torch version: 2.5.1
3
  • can you post the versions of cuda, opencv, torch that you are using? its likely that you will need to find the weakest link (oldest working version) of these and downgrade the others to match... Commented Jun 20 at 16:41
  • @BryceSmith | I updated the question adding the requested information. Commented Jun 20 at 16:50
  • OpenCV uses OpenCL extensively, if you call the APIs the right way (with UMat objects). OpenCL can run on pretty much every GPU. Commented Jun 20 at 18:55

1 Answer 1

1

This Github Issue from 2024 on opencv-python is highlighting the same issue you're having right now and their resolution is to use the opencv-python-cuda-wheels fork. opencv-python-cuda-wheels's latest release is from Feb 2025 and they specify what versions of CUDA (12.8), Nvidia Video Codec SDK (12.2) and cuDNN (9.7.0).

If any of these library versions don't align with the default JupyterNotebook image that you're running (or they're not installed), you can always create a custom JupyeterNotebook Image and in the dockerfile definition plug in the CLI commands you'd need to build the image with the right libraries respective versions.

Sign up to request clarification or add additional context in comments.

2 Comments

| I tried this but it says works on Python 3.7 and I have the AWS Sagemaker Python version 3.12.9, do you think it is needed to change a parameter or something? I read from this other source that Python 3.12 is supported, however, I'm not sure how to make this version usable for opencv-python-cuda-wheels.
Same idea -- when you create your own custom jupyter notebook container image, make sure to install the right python version you need. In the link I sent on the bottom they show you the command they run to install the latest version of python (specifically RUN yum install -y python3 python3-pip (etc)). You'd just need to change part of that command instead to install python 3.7. This guide shows you how to do that! medium.com/@nnilesh7756/… (CentOS also uses yum as the package manger so this guide

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.