windows 安装 Tensorflow 并启用GPU 加速

本文参照官方文档,在windows上安装tensorflow,并且开启gpu加速

环境

Windows10
GTX 1070

安装后各组件版本

Python 3.6.4
tensorflow 1.5.0
CUDA Toolkit 9.0
cuDNN v7.0.5

安装 Anaconda

https://www.continuum.io/downloads
选择Python 3.6 的版本,下载后默认配置安装

安装完成可以注销下,使得环境变量生效

创建venv

conda create -n tensorflow pip python=3.6

激活venv & 安装

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

安装完成后,可以看下当前tf的版本

(tensorflow) D:\>pip list

tensorflow-gpu (1.5.0)
tensorflow-tensorboard (1.5.1)

安装cuda & cuDNN

tf 1.5 版本支持的cuda 版本为 9.0 (9.1是不行的),cuDNN 版本为7 (不是官方文档里的6)

CUDA

https://developer.nvidia.com/cuda-90-download-archive

下载后为可执行文件,使用默认配置安装即可。

cuDNN

下载需要先注册
https://developer.nvidia.com/rdp/cudnn-download

选择Download cuDNN v7.0.5 (Dec 5, 2017), for CUDA 9.0
下载
cudnn-9.0-windows10-x64-v7.zip

下载后找一个路径解压,将 bin文件路径配置到系统PATH里面(配置环境变量)

检查

# 先激活venv
C:\Users\u>activate tensorflow
(tensorflow) C:\Users\u>python
Python 3.6.4 |Anaconda, Inc.| (default, Jan 16 2018, 10:22:32) [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-02-17 13:29:11.026439: I C:\tf_jenkins\workspace\rel-win\M\windows-gpu\PY\36\tensorflow\core\platform\cpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX AVX2
2018-02-17 13:29:11.322431: I C:\tf_jenkins\workspace\rel-win\M\windows-gpu\PY\36\tensorflow\core\common_runtime\gpu\gpu_device.cc:1105] Found device 0 with properties:
name: GeForce GTX 1070 major: 6 minor: 1 memoryClockRate(GHz): 1.7845
pciBusID: 0000:01:00.0
totalMemory: 8.00GiB freeMemory: 6.63GiB
2018-02-17 13:29:11.326018: I C:\tf_jenkins\workspace\rel-win\M\windows-gpu\PY\36\tensorflow\core\common_runtime\gpu\gpu_device.cc:1195] Creating TensorFlow device (/device:GPU:0) -> (device: 0, name: GeForce GTX 1070, pci bus id: 0000:01:00.0, compute capability: 6.1)
>>> print(sess.run(hello))
b'Hello, TensorFlow!'
>>>

你可能感兴趣的:(windows 安装 Tensorflow 并启用GPU 加速)