Win10下安装Tensorflow(GPU)+CUDA8.0+cudnn6

第一步:安装cuda8.0(TensorFlow不支持cuda9.0版本,安装后会报错)


如果出现这种情况,可以从官方下载最新的显卡驱动,驱动安装后可以在C:\NVIDIA\DisplayDriver\385.41\Win10_64\International

找到ListDevices.txt与Display.Driver文件夹,选中并复制。重新运行cuda_8.0.61_win10.exe,并查看提取路径

C:\Users\zzx\AppData\Local\Temp\CUDA,当出现ListDevices.txt与Display.Driver文件夹时,将之前复制的

替换提取路径中的目标文件,然后检查系统时,会正常。安装时,选择自定义,全选,并安装。

第二步:安装cudnn6.0(cuda8.0与cudnn6.0搭配,cuda9.0和cudnn7.0搭配

将cudnn中的bin,include,lib三个文件夹覆盖替换C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0中的bin,include,lib

添加环境变量:


添加后好像应该重启才能生效。

第三步:安装TensorFlow,默认是CPU版本的,如果想安装GPU版本,必须将旧的CPU版本下载

pip uninstall tensorflow

pip install tensorflow-gpu来安装

如果安装出现timeout 手动下载(地址:https://pypi.python.org/pypi/tensorflow)然后pip install 文件名

附件:cuda8.0+cudnn6.0下载链接http://download.csdn.net/download/hegongxu/10146459

最后测试程序:


import tensorflow as tf
#Creates a graph.
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))
成功结果:
2017-12-05 15:38:37.632186: I C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\35\tensorflow\core\platform\cpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX AVX2
2017-12-05 15:38:38.586136: I C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\35\tensorflow\core\common_runtime\gpu\gpu_device.cc:1030] Found device 0 with properties: 
name: GeForce GTX 1050 major: 6 minor: 1 memoryClockRate(GHz): 1.493
pciBusID: 0000:01:00.0
totalMemory: 2.00GiB freeMemory: 1.62GiB
2017-12-05 15:38:38.586528: I C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\35\tensorflow\core\common_runtime\gpu\gpu_device.cc:1120] Creating TensorFlow device (/device:GPU:0) -> (device: 0, name: GeForce GTX 1050, pci bus id: 0000:01:00.0, compute capability: 6.1)
Device mapping:
/job:localhost/replica:0/task:0/device:GPU:0 -> device: 0, name: GeForce GTX 1050, pci bus id: 0000:01:00.0, compute capability: 6.1
2017-12-05 15:38:38.661303: I C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\35\tensorflow\core\common_runtime\direct_session.cc:299] Device mapping:
/job:localhost/replica:0/task:0/device:GPU:0 -> device: 0, name: GeForce GTX 1050, pci bus id: 0000:01:00.0, compute capability: 6.1


MatMul: (MatMul): /job:localhost/replica:0/task:0/device:GPU:0
b: (Const): /job:localhost/replica:0/task:0/device:GPU:0
a: (Const): /job:localhost/replica:0/task:0/device:GPU:0
2017-12-05 15:38:38.665996: I C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\35\tensorflow\core\common_runtime\placer.cc:874] MatMul: (MatMul)/job:localhost/replica:0/task:0/device:GPU:0
2017-12-05 15:38:38.666324: I C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\35\tensorflow\core\common_runtime\placer.cc:874] b: (Const)/job:localhost/replica:0/task:0/device:GPU:0
2017-12-05 15:38:38.666690: I C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\35\tensorflow\core\common_runtime\placer.cc:874] a: (Const)/job:localhost/replica:0/task:0/device:GPU:0
[[ 22.  28.]
 [ 49.  64.]]


猜你喜欢

转载自blog.csdn.net/hegongxu/article/details/78720515