1. 程式人生 > >Tensorflow-GPU環境安裝

Tensorflow-GPU環境安裝

環境

WIN10+tensorflow1.8.0+cuda_9.0+cudnn

安裝資源

Anaconada:
連結:https://pan.baidu.com/s/1LAIXiolBb_RCbYmcxVQoDA 密碼:knak
CUDA:
連結:https://pan.baidu.com/s/1SxvJz-sq-A9DvGNx9ukvOA 密碼:quj2
CUDNN:
連結:https://pan.baidu.com/s/1DzTTIOqJi5hSrnG1eo7PFA 密碼:narz

安裝步驟

一一安裝即可,沒什麼特別的地方,網上也有很多安裝詳情可檢視

問題一

問題詳情:pip版本過低
You are using
pip version 9.0.1, however version 9.0.3 is available. You should consider upgrading via the 'python -m pip install --upgrade pip' command. 解決方案: 執行如下命令升級 python -m pip install --upgrade pip

問題二

>>> import tensorflow as tf
Traceback (most recent call last):
  File "<stdin>", line 1
, in <module> File "E:\Anaconda\lib\site-packages\tensorflow\__init__.py", line 24, in <module> from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import File "E:\Anaconda\lib\site-packages\tensorflow\python\__init__.py", line 47, in <module> import
numpy as np File "E:\Anaconda\lib\site-packages\numpy\__init__.py", line 142, in <module> from . import add_newdocs ImportError: cannot import name 'add_newdocs' 解決方案: 升級一下numpy即可 pip install -U numpy

問題三

注意CUDNN與CUDA版本的對應,先列出的都是相對應的,只是第一次安裝時隨便選了版本沒對應被坑了

驗證

驗證示例:
import tensorflow as tf
a = tf.constant([1.0,2.0,3.0], shape=[3], name='agrv-a')
b = tf.constant([2.0,3.0,4.0], shape=[3], name='argv-b')
c = a+b
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
print(sess.run(c))
正常結果如下:
E:\Anaconda\lib\site-packages\h5py\__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
  from ._conv import register_converters as _register_converters
2018-06-08 15:19:34.730123: I T:\src\github\tensorflow\tensorflow\core\platform\cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
2018-06-08 15:19:35.161155: I T:\src\github\tensorflow\tensorflow\core\common_runtime\gpu\gpu_device.cc:1356] Found device 0 with properties: 
name: GeForce GTX 960M major: 5 minor: 0 memoryClockRate(GHz): 1.176
pciBusID: 0000:01:00.0
totalMemory: 4.00GiB freeMemory: 3.35GiB
2018-06-08 15:19:35.161654: I T:\src\github\tensorflow\tensorflow\core\common_runtime\gpu\gpu_device.cc:1435] Adding visible gpu devices: 0
2018-06-08 15:20:44.901867: I T:\src\github\tensorflow\tensorflow\core\common_runtime\gpu\gpu_device.cc:923] Device interconnect StreamExecutor with strength 1 edge matrix:
2018-06-08 15:20:44.902185: I T:\src\github\tensorflow\tensorflow\core\common_runtime\gpu\gpu_device.cc:929]      0 
2018-06-08 15:20:44.902471: I T:\src\github\tensorflow\tensorflow\core\common_runtime\gpu\gpu_device.cc:942] 0:   N 
2018-06-08 15:20:44.902857: I T:\src\github\tensorflow\tensorflow\core\common_runtime\gpu\gpu_device.cc:1053] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 3083 MB memory) -> physical GPU (device: 0, name: GeForce GTX 960M, pci bus id: 0000:01:00.0, compute capability: 5.0)
Device mapping:
/job:localhost/replica:0/task:0/device:GPU:0 -> device: 0, name: GeForce GTX 960M, pci bus id: 0000:01:00.0, compute capability: 5.0
2018-06-08 15:20:46.676721: I T:\src\github\tensorflow\tensorflow\core\common_runtime\direct_session.cc:284] Device mapping:
/job:localhost/replica:0/task:0/device:GPU:0 -> device: 0, name: GeForce GTX 960M, pci bus id: 0000:01:00.0, compute capability: 5.0

add: (Add): /job:localhost/replica:0/task:0/device:GPU:0
2018-06-08 15:20:48.220730: I T:\src\github\tensorflow\tensorflow\core\common_runtime\placer.cc:886] add: (Add)/job:localhost/replica:0/task:0/device:GPU:0
argv-b: (Const): /job:localhost/replica:0/task:0/device:GPU:0
2018-06-08 15:20:48.221390: I T:\src\github\tensorflow\tensorflow\core\common_runtime\placer.cc:886] argv-b: (Const)/job:localhost/replica:0/task:0/device:GPU:0
agrv-a: (Const): /job:localhost/replica:0/task:0/device:GPU:0
2018-06-08 15:20:48.222161: I T:\src\github\tensorflow\tensorflow\core\common_runtime\placer.cc:886] agrv-a: (Const)/job:localhost/replica:0/task:0/device:GPU:0
[3. 5. 7.]