Windows10中安装tensorflow-cpu为tensorflow-gpu、CUDA、cuDNN

windows+CUDA9.0+cuDNN9.0即可

一、安装CUDA
1.准备好NVIDIA的显卡,下载安装CUDA
https://developer.nvidia.com/cuda-downloads
2.安装好之后把CUDA安装目录下的bin和lib\x64添加到

Path环境变量中

二、安装cuDNN
1.cuDNN下载
https://developer.nvidia.com/rdp/cudnn-download
2.解压压缩包,把压缩包中bin,include,lib中的文件
分别拷贝到C:\Program Files\NVIDIA GPU Computing
Toolkit\CUDA\v9.0目录下对应目录中
3.把C:\Program Files\NVIDIA GPU Computing
Toolkit\CUDA\v9.0\extras\CUPTI\libx64\cupti64_90.dll
拷贝到C:\Program Files\NVIDIA GPU Computing
Toolkit\CUDA\v9.0\bin

三、安装tensorflow-gpu
1.pip uninstall tensorflow
2.pip install tensorflow-gpu

四、最后在python中测试

import tensorflow as tf
a = tf.constant([1.,2.,3.,4.,5.,6.], shape=[2,3], name='a')
b = tf.constant([1.,2.,3.,4.,5.,6.], shape=[3,2], name='b')
c = tf.matmul(a,b)

with tf.Session(config= tf.ConfigProto(log_device_placement=True)) as sess:

    print(sess.run(c))



得到结果截图如下,包含了gpu信息即安装成功

In [1]: import tensorflow as tf
   ...: a = tf.constant([1.,2.,3.,4.,5.,6.], shape=[2,3], name='a')
   ...: b = tf.constant([1.,2.,3.,4.,5.,6.], shape=[3,2], name='b')
   ...: c = tf.matmul(a,b)
   ...:
   ...: with tf.Session(config= tf.ConfigProto(log_device_placement=True)) as sess:
   ...:     print(sess.run(c))
   ...:
2018-03-08 09:11:09.660245: I C:\tf_jenkins\workspace\rel-win\M\windows-gpu\PY\35\tensorflow\core\platform\cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
2018-03-08 09:11:09.992262: I C:\tf_jenkins\workspace\rel-win\M\windows-gpu\PY\35\tensorflow\core\common_runtime\gpu\gpu_device.cc:1212] Found device 0 with properties:
name: Quadro P600 major: 6 minor: 1 memoryClockRate(GHz): 1.5565
pciBusID: 0000:01:00.0
totalMemory: 2.00GiB freeMemory: 1.62GiB
2018-03-08 09:11:09.992521: I C:\tf_jenkins\workspace\rel-win\M\windows-gpu\PY\35\tensorflow\core\common_runtime\gpu\gpu_device.cc:1312] Adding visible gpu devices: 0
2018-03-08 09:11:10.579803: I C:\tf_jenkins\workspace\rel-win\M\windows-gpu\PY\35\tensorflow\core\common_runtime\gpu\gpu_device.cc:993] Creating TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 1384 MB memory) -> physical GPU (device: 0, name: Quadro P600, 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: Quadro P600, pci bus id: 0000:01:00.0, compute capability: 6.1
2018-03-08 09:11:10.820950: I C:\tf_jenkins\workspace\rel-win\M\windows-gpu\PY\35\tensorflow\core\common_runtime\direct_session.cc:297] Device mapping:
/job:localhost/replica:0/task:0/device:GPU:0 -> device: 0, name: Quadro P600, pci bus id: 0000:01:00.0, compute capability: 6.1


MatMul: (MatMul): /job:localhost/replica:0/task:0/device:GPU:0
2018-03-08 09:11:10.824576: I C:\tf_jenkins\workspace\rel-win\M\windows-gpu\PY\35\tensorflow\core\common_runtime\placer.cc:875] MatMul: (MatMul)/job:localhost/replica:0/task:0/device:GPU:0
b: (Const): /job:localhost/replica:0/task:0/device:GPU:0
2018-03-08 09:11:10.827072: I C:\tf_jenkins\workspace\rel-win\M\windows-gpu\PY\35\tensorflow\core\common_runtime\placer.cc:875] b: (Const)/job:localhost/replica:0/task:0/device:GPU:0
a: (Const): /job:localhost/replica:0/task:0/device:GPU:0
2018-03-08 09:11:10.829669: I C:\tf_jenkins\workspace\rel-win\M\windows-gpu\PY\35\tensorflow\core\common_runtime\placer.cc:875] a: (Const)/job:localhost/replica:0/task:0/device:GPU:0
[[22. 28.]
 [49. 64.]]


In [2]:

发布了24 篇原创文章 · 获赞 60 · 访问量 15万+

猜你喜欢

转载自blog.csdn.net/ccnucb/article/details/79479542