windows下tensorflow的安装

  |   0 评论   |   734 浏览

前方

最后搞了台 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!'

来源

评论

发表评论

validate