windows10安装tensorflow GPU版
2019年1月7日
参考官方教程:https://www.tensorflow.org/install/source_windows
官方教程最后给出各个工具包的对应版本如下:
GPU
Version | Python version | Compiler | Build tools | cuDNN | CUDA |
---|---|---|---|---|---|
tensorflow_gpu-1.12.0 | 3.5-3.6 | MSVC 2015 update 3 | Bazel 0.15.0 | 7 | 9 |
tensorflow_gpu-1.11.0 | 3.5-3.6 | MSVC 2015 update 3 | Bazel 0.15.0 | 7 | 9 |
tensorflow_gpu-1.10.0 | 3.5-3.6 | MSVC 2015 update 3 | Cmake v3.6.3 | 7 | 9 |
tensorflow_gpu-1.9.0 | 3.5-3.6 | MSVC 2015 update 3 | Cmake v3.6.3 | 7 | 9 |
tensorflow_gpu-1.8.0 | 3.5-3.6 | MSVC 2015 update 3 | Cmake v3.6.3 | 7 | 9 |
tensorflow_gpu-1.7.0 | 3.5-3.6 | MSVC 2015 update 3 | Cmake v3.6.3 | 7 | 9 |
tensorflow_gpu-1.6.0 | 3.5-3.6 | MSVC 2015 update 3 | Cmake v3.6.3 | 7 | 9 |
tensorflow_gpu-1.5.0 | 3.5-3.6 | MSVC 2015 update 3 | Cmake v3.6.3 | 7 | 9 |
tensorflow_gpu-1.4.0 | 3.5-3.6 | MSVC 2015 update 3 | Cmake v3.6.3 | 6 | 8 |
一 : 已安装了python3.6版的Anaconda3 (64-bit)
二:安装CUDA和cuDNN
下载cuda: https://developer.nvidia.com/cudnn 和cudnn: https://developer.nvidia.com/cuda-zone
cudnn要对应cuda的版本:cuda9.0.176对应的cudnn版本为V7.4.2.24
安装cuda全按默认选项一路“下一步”
我的CUDA目录路径为: C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0
安装cudnn参考官方:https://docs.nvidia.com/deeplearning/sdk/cudnn-install/index.html#installwindows
解压缩cuDNN包将以下文件复制到CUDA Toolkit目录中。
- 复制 bin\cudnn64_7.dll 至 C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\bin。
- 复制 include\cudnn.h 至 C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\include。
- 复制 lib\64\cudnn.lib 至 C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\lib\x64。
验证:
1 2 3 4 5 |
C:\Users\qi hong lu>nvcc --version 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 |
系统环境变量:
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\bin
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\extras\CUPTI\libx64
三:安装tensorflow
在pip install tensorflow_gpu==1.12.0之前先pip uninstall tensorflow和pip uninstall tensorflow-gpu
验证:
1 2 3 4 5 6 7 8 9 10 |
C:\Users\qi hong lu>python Python 3.6.7 |Anaconda, Inc.| (default, Dec 10 2018, 20:35:02) [MSC v.1915 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import tensorflow as tf >>> sess = tf.Session() >>> a = tf.constant(10) >>> b= tf.constant(12) >>> sess.run(a+b) 22 >>> |
Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
在开头加上这两行可以解决:
1 2 |
import os os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' |
检查可用设备:
1 2 |
>>>from tensorflow.python.client import device_lib >>>print(device_lib.list_local_devices()) |
正常会检测到有GPU可用: