简体   繁体   English

使用 OpenCV Python API 指定 GPU 设备

[英]Specify GPU device with OpenCV Python API

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:在使用 Tensorflow(带 GPU 支持)处理从 OpenCV(3.4.3,使用 Python API)捕获中提取的一些特征的项目时,每当我尝试从捕获中read时,都会收到来自 cuDNN 的以下错误在我开始 tf 会话后:

F1028 02:37:31.456640 xxxxx cudnn_conv_layer.cu:28] Check failed: status == CUDNN_STATUS_SUCCESS (8 vs. 0) CUDNN_STATUS_EXECUTION_FAILED F1028 02:37:31.456640 xxxxx cudnn_conv_layer.cu:28] 检查失败:状态 == CUDNN_STATUS_SUCCESS(8 对 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.我想问题在于 OpenCV 和 Tensorflow 同时通过 CUDA 使用 GPU,并且 GPU 内存不足。 The workaround I am currently using is to start capturing with OpenCV first, and then start the tf session whenever it is actually needed.我目前使用的解决方法是首先使用 OpenCV 开始捕获,然后在实际需要时启动 tf 会话。 This way, TensorFlow knows that the GPU is busy and opted to use CPU only.这样,TensorFlow 就知道 GPU 很忙,并选择仅使用 CPU。 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.考虑到我只使用 OpenCV 进行捕获和基本预处理,我认为不需要 GPU 支持,最好让 TensorFlow 使用 GPU。

Is there a way to specify which GPU device to use with OpenCV Python API (or if it should use GPU at all)?有没有办法指定哪个 GPU 设备与 OpenCV Python API 一起使用(或者它是否应该使用 GPU)? I see with the C++ API there is a setDevice() method under the gpu namespace.我看到 C++ API 在gpu命名空间下有一个setDevice()方法。 Is there an equivalent for the Python API? Python API 是否有等价物?

Here is the equivalent call for the Python API, it is under 'cuda':这是对 Python API 的等效调用,它位于“cuda”下:

cv2.cuda.setDevice(int device_id)

Source 来源

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM