Python3+Cuda+Cudnn+GPU window10上安装python+CUDA+CuDNN+TensorFlow

确认显卡支持 cuda

首先确认显卡是否是 英伟达 NVIDIA 的,当然 AMD 也支持,但是不常用;

NVIDIA 显卡有 GTX Geforce、Quadra 和 Tesla 三大系列,然后到如下网站查看是否支持 Cuda

https://developer.nvidia.com/cuda-gpus 

点击如下链接即可查看每个系列支持 cuda 的显卡版本

安装显卡驱动

在安装CUDA过程中,你可能各种尝试,把显卡驱动整坏了,可以重新安装;    【我就是这样,然后死活装不上 cuda,后来重装驱动,搞定】

在 https://www.nvidia.cn/Download/index.aspx?lang=cn 获取自己显卡的最新驱动版本;

下载,双击安装;

安装 cuda 驱动

访问CUDA的下载网站:https://developer.nvidia.com/cuda-toolkit,可以看到CUDA目前的最新版本,可以通过选择下面的“Legacy Releases”链接来下载旧版本的驱动;

建议选择自定义安装,然后只勾选cuda,建议安装在默认文件路径;

把 安装路径下的 bin 目录设为环境变量:C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\bin

 

安装 cudnn 库

CuDNN库(The NVIDIA CUDA® Deep Neural Network library)是CUDA针对深度神经网络的更新包,TensorFlow会使用它用于加速NVidia GPU上的深度学习。可以从这里下载,见:https://developer.nvidia.com/cudnn

首先要注册一个NVidia开发者帐号,它是免费的。登录后,您会看到各种CuDNN下载;

cuda 与 cudnn 版本要严格对应,对应关系见 https://developer.nvidia.com/rdp/cudnn-archive

 

下载下来的是一个包含了几个文件夹的ZIP文件,每个文件夹包含CuDNN文件(一个DLL,一个头文件和一个库文件)。找到你的CUDA安装目录,这里应该是这样的:

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0

可以看到从ZIP文件的目录也在这个目录,即有一个bin、一个include,一个lib等。将文件从ZIP复制到相关的目录。 

比如把cudnn64_7.dll文件拖拽到C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\bin目录,其它相似。

安装 tensorflow-gpu

首先安装 python3.6

具体过程参考我的其他博客,这里只记录重点

之前我讲过 python 安装不推荐 64 位的,所以我安装的是 32 位的,但是死活装不上 tf,报错如下

Could not find a version that satisfies the requirement tensorflow-gpu(from versions: )
No matching distribution found for  tensorflow-gpu

后来换成了 64 位,可以了,我也是醉了

然后使用 pip 安装 tensorflow

python3 -m pip install tensorflow-gpu

如果安装很慢,可以使用国内镜像源

python3 -m pip install tensorflow-gpu -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com

其中 --trusted-host pypi.douban.com 的作用是获得ssl证书的认证

验证是否安装成功

import tensorflow as tf
print('GPU', tf.test.is_gpu_available())        # GPU True

显示 GPU 可用,成功;

如果CUDA驱动程序有错误,就可能会显示 cudart64_XX.dll 失败,其中XX是版本号。

ImportError: Could not find 'cudart64_100.dll'. TensorFlow requires that this DLL be installed in a directory that is named in your %PATH% environment variable. 
Download and install CUDA 10.0 from this URL: https://developer.nvidia.com/cuda-90-download-archive

按照提示,要下载 cuda 10.0,tf1.13 以上的版本需要 cuda 10.0 版本

如果CUDA驱动程序正确,但CuDNN驱动程序有错误,就可能会显示说 cudnn64_X.dll 缺少什么东西,其中X是一个版本号。 

参考资料:

https://blog.csdn.net/hzk594512323/article/details/86082852  Python之pip安装失败----Could not find a version that satisfies the requirement xxxx(from versions: )

### 下面是 cuda 安装教程 

https://www.cnblogs.com/touch-skyer/p/8367706.html  window10上安装python+CUDA+CuDNN+TensorFlow      【主要参考】

https://blog.csdn.net/u014695788/article/details/93246548  python CUDA配置

https://zhuanlan.zhihu.com/p/29841665  用GPU加速深度学习: Windows安装CUDA+TensorFlow教程

https://www.360kuai.com/pc/9290487ad261e50da?cota=4&tj_url=so_rec&sign=360_57c3bbd1&refer_scene=so_1  tensorflow版本与cuda cuDNN版本对应关系

猜你喜欢

转载自www.cnblogs.com/yanshw/p/12068160.html
今日推荐