windows 下 tensorflow 的安装

本贴最后更新于 2056 天前,其中的信息可能已经时异事殊

前方

最后搞了台 windows + GPU 的机器,重新来走一遍 tensorflow 的安装过程。

过程

  1. 安装 CUDA 9.0
  2. 安装 cuDNN v7.0
  3. 安装 python 3.6.6
  4. 安装 tensorflow

安装 CUDA 9.0

最新版本的是 CUDA 9.2,这里为了避免不兼容问题,使用了官方推荐的 CUDA 9.0 版本

安装 cuDNN 7.0

最新版本的是 cuDNN 7.2,这里安装了 cuDNN v7.0.5 (Dec 5, 2017), for CUDA 9.0

安装 python 3.6.6

一种方式是直接安装官方的 python 3.6.6,具体略。

另一种方式是安装 Anaconda3,见清华镜像 anaconda

Anacoda3

先安装二进制包

再创建 tensorflow 环境

conda create -n tensorflow pip python=3.6

激活 conda 环境

activate tensorflow

安装 GPU 版本的 tensorflow

pip install --ignore-installed --upgrade tensorflow-gpu 

漫长的等待之后,安装完成。

检查安装的正确性

在 shell 中运行 Python,输入

>>>  import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
>>>  print(sess.run(hello))

正确结果

Hello, TensorFlow!

实际如下:

Python 3.6.6 |Anaconda, Inc.| (default, Jun 28 2018, 11:27:44) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
2018-09-10 00:21:24.555928: I T:\src\github\tensorflow\tensorflow\core\platform\cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
2018-09-10 00:21:25.003774: I T:\src\github\tensorflow\tensorflow\core\common_runtime\gpu\gpu_device.cc:1405] Found device 0 with properties:
name: GeForce GTX 950 major: 5 minor: 2 memoryClockRate(GHz): 1.2155
pciBusID: 0000:01:00.0
totalMemory: 2.00GiB freeMemory: 1.64GiB
2018-09-10 00:21:25.014811: I T:\src\github\tensorflow\tensorflow\core\common_runtime\gpu\gpu_device.cc:1484] Adding visible gpu devices: 0
2018-09-10 00:21:25.507829: I T:\src\github\tensorflow\tensorflow\core\common_runtime\gpu\gpu_device.cc:965] Device interconnect StreamExecutor with strength 1 edge matrix:
2018-09-10 00:21:25.513224: I T:\src\github\tensorflow\tensorflow\core\common_runtime\gpu\gpu_device.cc:971]      0
2018-09-10 00:21:25.517489: I T:\src\github\tensorflow\tensorflow\core\common_runtime\gpu\gpu_device.cc:984] 0:   N
2018-09-10 00:21:25.525505: I T:\src\github\tensorflow\tensorflow\core\common_runtime\gpu\gpu_device.cc:1097] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 1401 MB memory) -> physical GPU (device: 0, name: GeForce GTX 950, pci bus id: 0000:01:00.0, compute capability: 5.2)
>>> print(sess.run(hello))
b'Hello, TensorFlow!'

来源

  • TensorFlow

    TensorFlow 是一个采用数据流图(data flow graphs),用于数值计算的开源软件库。节点(Nodes)在图中表示数学操作,图中的线(edges)则表示在节点间相互联系的多维数据数组,即张量(tensor)。

    20 引用 • 19 回帖

相关帖子

欢迎来到这里!

我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。

注册 关于
请输入回帖内容 ...