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]:

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章