1.使用版本:
Python 3.6
CUDA 9.0
cuDNN (与CUDA版本对应)
tensorflow-gpu 1.8
注:可不安装anaconda和vs
2.下载CUDA并安装 https://developer.nvidia.com/cuda-toolkit-archive
(1)安装警告:The graphics driver could not find compatible graphics hardware。该错误可忽略。
(2)安装过程失败主要由于Visual Studio(VS) Intergration无法安装导致。选择自定义安装,不安装CUDA中的Visual Studio(VS) Intergration。
(3)验证是否安装成功:命令行 nvcc -V
配置环境变量,将CUDA安装目录下的bin和lib\x64配置到path中。
3.下载解压cuDNN https://developer.nvidia.com/rdp/cudnn-download
需要注册一下账号
一定要下载对应CUDA版本的cuDNN!!!
将解压后目录下的文件放置到CUDA安装目录下对应位置。lib放置lib目录下,以此类推。
4.安装tensorflow-gpu
(1)安装命令:
pip uninstall tensorflow(卸载cpu版本的tensorflow)
pip install tensorflow-gpu==1.8
如果出现错误:7201 (compatibility version 7200) but source was compiled with 7003 (compatibility version 7000). If using a binary install, upgrade your CuDNN library to match. If building from sources, make sure the library loaded at runtime matches a compatible version specified during compile configuration.类似,可能并不是cuDNN版本与CUDA不匹配,如果官网下的是匹配的,更大可能是由于tensorflow版本问题,可换更高版本试一试。
(2)测试是否安装成功:
import tensorflow as tf
test=tf.constant('hello gpu')
with tf.Session() as sess:
print(sess.run(test))
检查gpu
tf.test.is_gpu_available()
#返回true/false
tf.test.gpu_device_name()
#设备名称