解决PyTorch报错“no CUDA-capable device is detected”

在进行PyTorch调用GPU进行计算时,出现如下错误:

THCudaCheck FAIL file=/opt/conda/conda-bld/pytorch_1511304568725/work/torch/lib/THC/THCGeneral.c line=70 error=38 : no CUDA-capable device is detected
...
RuntimeError: cuda runtime error (38) : no CUDA-capable device is detected at /opt/conda/conda-bld/pytorch_1511304568725/work/torch/lib/THC/THCGeneral.c:70

解决方法:

S1. 新建终端窗口,运行命令sudo nvidia-settings,在弹出的NVIDIA窗口中查看自己的显卡编号,如下图所示:
解决PyTorch报错“no CUDA-capable device is detected”_第1张图片
S2. 打开相应的Python源码文件,查找形如os.environ["CUDA_VISIBLE_DEVICES"]的代码行,将右边的数字改为上述查看的显卡编号,如下图所示:
解决PyTorch报错“no CUDA-capable device is detected”_第2张图片

至此,问题解决。

你可能感兴趣的:(Ubuntu,深度学习(Deep,learning),CUDA,Python,PyTorch,Debug,数字图像处理,模式识别与深度学习)