第一部分 开篇提醒
安装时一定要注意版本匹配!一定要注意版本匹配!一定要注意版本匹配!重要的事情说三遍。
另外,安装顺序也很重要,一定要先安装cuda和cudnn,再安装tensorflow包,亲测时,因为安装顺序的问题始终无法运行GPU。
第二部分 安装过程
目前在win7下搭建环境时安装的版本为:
python 3.5 + tensflow-gpu 1.1.0 + cuda 8.0 + cudnn 9.1
cuda安装包 cuda_8.0.61_windows.exe
版本下载链接:https://developer.nvidia.com/cuda-toolkit-archive
cudnn安装包 cudnn-8.0-windows7-x64-v5.1
版本下载链接:https://developer.nvidia.com/rdp/form/cudnn-download-survey
$conda update conda
$conda create -n py35 python=3.5 anaconda
$activate py35
$conda list
$conda install tensorflow-gpu
$conda install keras
第三部分 验证环境
1、测试代码
import tensorflow as tf
print(tf.__version__)
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
#print(sess.run(hello))
a = tf.constant(10)
b = tf.constant(32)
#print(sess.run(a + b))
# test for gpu #
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)
#Creates a session with log_device_placement set to True.
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
#Runs the op.
print(sess.run(c))
2、查看GPU的使用率
nvidia-smi -q -g 0 -d UTILIZATION -l
第四部分 参考文档
http://blog.sina.com.cn/s/blog_14935c5880102wu86.html