所需软件的安装版本
| 软件 | 版本 |
|---|---|
| Anaconda | Python 3.5.2 :: Anaconda 4.2.0 (64-bit) |
| CUDA | cuda_9.0.176_win10 |
| CuDNN | cudnn-9.0-windows10-x64-v7.1 |
不想去一个一个下载,我帮你都整理好了,TensorFlow安装套件 百度云下载地址:
链接:https://pan.baidu.com/s/1wSvXlwE12GTw27kKYkOBcQ 密码:9ot5
安装步骤:
安装Anaconda
这个很简单,直接下载安装包,下一步就行了。
检测是否支持CUDA
NVIDIA官网查询,具体见:https://developer.nvidia.com/cuda-gpus,就可以知道是否可以使用带GPU支持的TensorFlow。在安装和运行TensorFlow之前,需要先安装CUDA驱动。
安装CUDA驱动
访问CUDA的下载网站:https://developer.nvidia.com/cuda-toolkit,可以看到CUDA目前的最新版本是9.1版,可以通过选择下面的“Legacy Releases”链接来下载旧版本的驱动。
建议选择自定义安装,然后只勾选cuda。建议安装在默认文件路径。
安装完之后系统变量会自动为你添加上,这个不用管。 测试一下是否安装成功,命令行输入 nvcc -V ,看到版本信息就表示安装成功了
PS C:\WINDOWS\system32> nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2017 NVIDIA Corporation
Built on Fri_Sep__1_21:08:32_Central_Daylight_Time_2017
Cuda compilation tools, release 9.0, V9.0.176
安装CuDNN库
CuDNN库(The NVIDIA CUDA® Deep Neural Network library)是CUDA针对深度神经网络的更新包,TensorFlow会使用它用于加速NVidia GPU上的深度学习。可以从这里下载,见:https://developer.nvidia.com/cudnn。
首先要注册一个NVidia开发者帐号,它是免费的。登录后,您会看到各种CuDNN下载。本文下载使用了CUDA 9.0,所以确定为CUDA 9.0选择了cuDNN v9.0.5。
其实这个是一个压缩包,解压放到任何一个目录下就行,然后把其中的bin目录路径添加到Path环境变量里。
安装TensorFlow
由于 Google 那帮人已经把 TensorFlow 打成了一个 pip 安装包,所以现在可以用正常安装包的方式安装 TensorFlow 了,就是进入命令行执行下面这一条简单的语句:
注意要使用管理员权限,即在搜索框输入cmd,然后右键,选择已管理员身份运行
# GPU版本
pip3 install --upgrade tensorflow-gpu
# CPU版本
pip3 install --upgrade tensorflow
测试
用一个简单的矩阵乘法测试一下
import tensorflow as tf
a = tf.random_normal((100, 100))
b = tf.random_normal((100, 500))
c = tf.matmul(a, b)
sess = tf.InteractiveSession()
sess.run(c)
实际运行情况
In [1]: import tensorflow as tf
In [2]: a = tf.random_normal((100, 100))
In [3]: b = tf.random_normal((100, 500))
In [4]: c = tf.matmul(a, b)
In [5]: sess = tf.InteractiveSession()
2018-04-14 17:53:51.821028: 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-04-14 17:53:52.299257: I T:\src\github\tensorflow\tensorflow\core\common_runtime\gpu\gpu_device.cc:1344] Found device 0 with properties:
name: GeForce GTX 1060 3GB major: 6 minor: 1 memoryClockRate(GHz): 1.759
pciBusID: 0000:01:00.0
totalMemory: 3.00GiB freeMemory: 2.44GiB
2018-04-14 17:53:52.304536: I T:\src\github\tensorflow\tensorflow\core\common_runtime\gpu\gpu_device.cc:1423] Adding visible gpu devices: 0
2018-04-14 17:56:02.203424: I T:\src\github\tensorflow\tensorflow\core\common_runtime\gpu\gpu_device.cc:911] Device interconnect StreamExecutor with strength 1 edge matrix:
2018-04-14 17:56:02.206562: I T:\src\github\tensorflow\tensorflow\core\common_runtime\gpu\gpu_device.cc:917] 0
2018-04-14 17:56:02.209008: I T:\src\github\tensorflow\tensorflow\core\common_runtime\gpu\gpu_device.cc:930] 0: N
2018-04-14 17:56:02.210820: I T:\src\github\tensorflow\tensorflow\core\common_runtime\gpu\gpu_device.cc:1041] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 2148 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1060 3GB, pci bus id: 0000:01:00.0, compute capability: 6.1)
In [6]: sess.run(c)
Out[6]:
array([[ 12.461744 , -2.763069 , 3.808689 , ..., 1.8473787,
-13.456398 , 15.942695 ],
[ 3.081438 , 3.7561693, -9.30651 , ..., 5.1801486,
-9.152332 , -5.1047654],
[ 13.291951 , 1.1641746, 1.1810235, ..., -10.287245 ,
3.4808588, -9.7852335],
...,
[-15.615421 , -14.173458 , -0.9662838, ..., 18.056751 ,
11.06031 , 17.826332 ],
[-20.06306 , 6.9881086, 11.5085125, ..., -9.407914 ,
5.9640474, -7.0610776],
[ 5.242064 , 4.342845 , -4.4574194, ..., -11.325852 ,
3.621978 , -10.848241 ]], dtype=float32)
In [7]:
4370

被折叠的 条评论
为什么被折叠?



