win10跑深度学习程序无法调用gpu的问题(已解决)

win10跑深度学习真的是一言难尽,但是windows系统又使用的比较习惯,过去使用过ubuntu系统,里面写文档什么的确实不习惯,所以自己做的实验项目也主要是以win10为主工具是常见的pycharm+anaconda+win10

采用的是keras2.3.1,更改了程序中一些代码之后,每次跑模型都会中断

把它写下来,以防类似的问题再次被遗忘。

[En]

Write it down to prevent similar problems from being forgotten again.

这是该程序每次运行以打开任务管理器时的外观。

[En]

This is what it looks like every time the program runs to open the task manager.

win10跑深度学习程序无法调用gpu的问题(已解决)

gpu是一点儿没出力。。。。我寻思你起码是个980Ti啊,你不出力要你有啥用。。。。

在pycharm的terminal终端输入python,进入python环境

在python中输入如下代码

from tensorflow.python.client import device_lib
print(device_lib.list_local_devices())

在terminal中发现

win10跑深度学习程序无法调用gpu的问题(已解决)

发现问题,检测不到gpu

只有一个cpu(-1)

经过我的询问和研究分析,可能会有很多种问题(血泪史)

[En]

After my inquiry and research analysis, there may be many kinds of problems (history of blood and tears)

1,tensorflow版本与显卡版本不对应(或者没有安装对应gpu版本)

win10跑深度学习程序无法调用gpu的问题(已解决)

2,cudnn与cuda和相应的python版本以及对应的tensorflow或keras版本不对应

1,2解决方法很简单,寻找对应的版本重新安装即可,网上教程很多,有的是使用代码在终端加载,有的是在英伟达官网下载文件安装,这些方法都可以的,

你也可以尝试重新安装显卡驱动程序或更新显卡驱动程序,但我的问题不在这里,所以我不会重复,但我仍然需要尝试。

[En]

You can also try to reinstall the video driver or update the video driver, but my problem is not here, so I won’t repeat it, but I still need to try.

3,代码未调用gpu

尝试在运行程序的标题中输入以下代码

[En]

Try to enter the following code in the header of the running program

import os
os.environ["CUDA_VISIBLE_DEVICES"] = "0"    #使用的gpu的编号,使用第 0 个

但是显然我的gpu都识别不到,问题也并不在这里

4,anaconda下的环境在pycharm中并未进入

这是我所存在的问题

在conda下创建的环境在pycharm中进入 File Setting

win10跑深度学习程序无法调用gpu的问题(已解决)

在project中选择interpreter

右侧python interpreter 选中所需conda的环境

win10跑深度学习程序无法调用gpu的问题(已解决)

但是

但是

对于我的电脑pycharm来讲,并没有进入这个虚拟环境,到现在我都不知道为什么,同样的设定在其他电脑上就行。。。。

比如在pycharm terminal中输入

conda info --envs

会发现

win10跑深度学习程序无法调用gpu的问题(已解决)

我的程序依然在pycharm中处于base环境中。而非创建的虚拟环境里

https://zhuanlan.zhihu.com/p/441469719

用了上述的方法之后

win10跑深度学习程序无法调用gpu的问题(已解决)

这是进入的唯一途径(个人认为)

[En]

This is the only way to enter (personally think)

5,缺少必要的cuda组件(个人认为有可能是win10跑程序的bug,这也是我一直以来未发现的核心问题)

之前一直会或多或少的提示缺少cudnn某某组件,但是没有注意,全心全意的在解决环境的问题,环境的问题解决了也没有类似提示了

当我认为它终于完成的时候,再来一次。

[En]

When I think it’s finally done, again.

from tensorflow.python.client import device_lib
print(device_lib.list_local_devices())

结果

win10跑深度学习程序无法调用gpu的问题(已解决)

我真不敢相信我还是认不出来。请不要理会我犯的几次打错代码的愚蠢错误。)

[En]

I can’t believe I still can’t recognize it. Please ignore my stupid mistake of typing the wrong code several times. )

从我在下面的图片中写的研究记录来看,我的心情很不好。

[En]

Judging from the research records I wrote in the picture below, I was in a bad mood.

win10跑深度学习程序无法调用gpu的问题(已解决)

但这位敬业的人发现了问题,这是值得的。

[En]

But it is worth the effort that the dedicated person found the problem.

could not locate zlibwapi.dll Please make sure it is in your library path.

从官网下载所需组件并将其添加到path中

官方网站地址

https://docs.nvidia.com/deeplearning/cudnn/install-guide/index.html#install-zlib-windows

添加到path中或者是添加到cuda

右键此电脑 —-属性——-高级系统设置

win10跑深度学习程序无法调用gpu的问题(已解决)

环境变量——path——–添加

path路径添加zlib123.dll.zip解压后的zlibwaip.dll路径

然后再次尝试

win10跑深度学习程序无法调用gpu的问题(已解决)

可以发现有-1和0号两张卡

cpu 与gpu全都能识别到

解决了。。。。撒花

总结一下,如果有能力,除了看中文资料外,可以Google一下适当参考一些英文论坛上的信息或者官方网站,确实多用一门语言,就会有更多的想法可以参考。

Original: https://blog.csdn.net/qq_44104483/article/details/125521779
Author: Sawyer Zhang
Title: win10跑深度学习程序无法调用gpu的问题(已解决)

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/495987/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球