1、CUDA的下载,官网下载CUDA版本一般是最新版本,但是TensorFlow版本与CUDA版本可能不兼容,CUDA其他版本下载地址是https://developer.nvidia.com/cuda-toolkit-archive ,可以根据自己的需要下载CUDA的版本。我下载的是CUDA9.0

2、双击可执行文件,选择解压路径,点击OK

TensorFlow 安装GPU版本

 

3、正在解压

TensorFlow 安装GPU版本

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

4、检查系统的兼容性

TensorFlow 安装GPU版本

 

5、点击继续

TensorFlow 安装GPU版本

 

6、点击同意并继续

TensorFlow 安装GPU版本

 

7、选择精简安装选项,点击下一步

TensorFlow 安装GPU版本

 

8、正在安装

TensorFlow 安装GPU版本

 

TensorFlow 安装GPU版本

 

 

9、点击下一步结束安装

TensorFlow 安装GPU版本

 

10、点击关闭

TensorFlow 安装GPU版本

 

11、在dos窗口中输入nvcc -V,如果输出是cuda版本信息,则说明安装成功

TensorFlow 安装GPU版本

 

2、下载CUDNN7.0,因为这样才能跟CUDA进行环境的搭建,下载地址是:https://developer.nvidia.com/rdp/cudnn-archive,在下载CUDNN7.0之前,会提示你注册一个账号,输入邮箱等相关注册信息注册一个账号,然后用注册的账号进行登录就可以进行下载。

3、将下载的CUDNNV7.0解压,打开里面的文件夹,找到里面的bin、include、lib文件夹,将这三个文件夹复制到安装CUDA9.0的路径覆盖原有的文件。本机的安装路径为:C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0

TensorFlow 安装GPU版本

 

4、本机装的是anaconda3.4.1,打开dos窗口,通过调用以下命令创建名为TensorFlow的conda环境

C:\Users\Administrator> conda create -n tensorflow pip python=3.5,命令执行完后在输入框输入y

TensorFlow 安装GPU版本

4、输入y后正在下载一些需要的包,下载完成后输入activate tensorflow**conda环境

TensorFlow 安装GPU版本

 

5、发出相应的命令在conda环境中安装TensorFlow,因为本机安装的是GPU版,所以输入如下命令:

pip install --ignore-installed --upgrade tensorflow-gpu

TensorFlow 安装GPU版本

 

 

 

6、安装完成后,输入黄色字体提示的命令,python -m pip install --upgrade pip ,等待命令执行完毕即可。

TensorFlow 安装GPU版本

 

7、验证TensorFlow是否安装成功

本机是通过anaconda安装的,首先要**anaconda环境,打开doc窗口,输入**命令activate tensorflow,然后从shell中调用Python,在dos窗口中输入Python即可调用成功。

TensorFlow 安装GPU版本

8、在Python交互式解释器中输入以下几行代码

>>> import tensorflow as tf

>>>hello = tf.constant('Hello,Tensorflow!')

>>>sess = tf.Session()

>>>print(sess.run(hello))

如果窗口中输出是b'Hello,Tensorflow',则说明已经成功。

TensorFlow 安装GPU版本

 

 

9、在Pycharm中判断TensorFlow是GPU版本还是CPU版本只需运行如下程序,然后就可以在输出窗口中看到结果,下图所示的就说明计算机安装的是GPU版本。

import numpy

import tensorflow as tf

a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')

b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b')

c = tf.matmul(a, b)

sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))

print(sess.run(c))

TensorFlow 安装GPU版本

 

10、验证cuDNN的配置

打开anaconda Prompt,输入Python,再输入import TensorFlow,如果没有提示没有安装CUDNN,则cuDNN配置成功了。

TensorFlow 安装GPU版本

 

 

相关文章: