-2
opencv
config_error
ai_generated
partial
cv2.error: OpenCV(4.7.0) /modules/dnn/src/dnn.cpp: 错误: (-2:未指定错误) DNN 模块未使用 CUDA 后端构建;已切换到 CPU
cv2.error: OpenCV(4.7.0) /modules/dnn/src/dnn.cpp: error: (-2:Unspecified error) DNN module was not built with CUDA backend; switched to CPU
ID: opencv/dnn-cuda-backend-missing
75%修复率
90%置信度
1证据数
2023-08-15首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 4.5.0 | active | — | — | — |
| 4.6.0 | active | — | — | — |
| 4.7.0 | active | — | — | — |
| 4.8.0 | active | — | — | — |
| 4.9.0 | active | — | — | — |
根因分析
OpenCV 安装未包含 DNN 的 CUDA 支持,因此 GPU 加速不可用,回退到 CPU。
English
The OpenCV installation does not include CUDA support for DNN, so GPU acceleration is unavailable and falls back to CPU.
官方文档
https://docs.opencv.org/4.x/d2/d58/tutorial_dnn_googlenet.html解决方案
-
Rebuild OpenCV from source with CUDA enabled: set -DWITH_CUDA=ON and -DWITH_CUDNN=ON in CMake, and ensure CUDA toolkit and cuDNN are installed.
-
Use a pre-built OpenCV package that includes CUDA support, such as from conda-forge (opencv with cuda variant) or NVIDIA's official Docker images.
无效尝试
常见但无效的做法:
-
Set environment variable OPENCV_DNN_CUDA=1
95% 失败
This environment variable does not exist; CUDA support must be compiled into OpenCV.
-
Install CUDA toolkit after OpenCV installation
85% 失败
CUDA toolkit must be present at build time; installing it after does not add CUDA support to an existing OpenCV build.
-
Use cv2.dnn.setPreferableBackend(cv2.dnn.DNN_BACKEND_CUDA) to force CUDA
90% 失败
If the DNN module was not built with CUDA, this call will throw the same error; it does not enable CUDA at runtime.