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

猜你喜欢

转载自blog.csdn.net/Noonebirdyou/article/details/80624387