Ask Your Question

Specify GPU device with Python API

asked 2018-11-04 14:44:43 -0500

guguke gravatar image

updated 2018-11-04 14:48:16 -0500

When working on a project using Tensorflow (w/ GPU support) to process some features extracted from OpenCV (3.4.3, using Python API) captures in real time, I am getting the following error from cuDNN whenever I try to read from the capture after I start the tf session:

F1028 02:37:31.456640 xxxxx] Check failed: status == CUDNN_STATUS_SUCCESS (8 vs. 0) CUDNN_STATUS_EXECUTION_FAILED

I suppose that the issue is with OpenCV and Tensorflow both using GPU via CUDA at the same time and that the GPU ran out of memory. The workaround I am currently using is to start capturing with OpenCV first, and then start the tf session whenever it is actually needed. This way, TensorFlow knows that the GPU is busy and opted to use CPU only. However, the frame rate drops significantly as a result.

Considering that I only use OpenCV for capturing and basic preprocessing, I don't think GPU support is necessary and it would be preferable to let TensorFlow use the GPU.

Is there a way to specify which GPU device to use with OpenCV Python API (or if it should use GPU at all)? I see with the C++ API there is a setDevice() method under the gpu namespace. Is there an equivalent for the Python API?

edit retag flag offensive close merge delete


opencv2.4 had a gpu namespace, current 3.4.3 has a cuda one. (but none of it matters for python)

berak gravatar imageberak ( 2018-11-05 06:30:31 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2018-11-05 04:54:52 -0500

berak gravatar image

updated 2018-11-05 06:27:14 -0500

opencv's current (3.4.3) python api does not use CUDA at all, it is also entirely unrelated to tensorflow, so you won't be able to change any TF/CUDA/GPU settings using cv2 functions

there might be a way to configure tensorflow from python, but we cannot help you with it from here.

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2018-11-04 14:44:43 -0500

Seen: 752 times

Last updated: Nov 05 '18