官網安裝方法:
https://www.tensorflow.org/install/install_windows
1.pip
2.Anaconda
3.源碼:http://www.lxweimin.com/p/d0a5fa97fcc8
說明:使用pip或anaconda等方式安裝的預編譯好的tensorflow沒有AVX2指令集加速,通過手動編譯可以更好的利用GPU。但是如果沒有AVX或者GPU的話,手動編譯幾乎沒有優勢。
目前,官方只提供了Ubuntu和Mac OS X的編譯支持,在Windows下可以通過Bazel和CMake兩種方式進行編譯,但只是 “highly experimental”,可能會遇到各種錯誤。
可供參考的其他安裝方法:
http://blog.csdn.net/wx7788250/article/details/60877166
http://blog.csdn.net/JerryZhang__/article/details/60763161
開始安裝
前提條件
windows平臺安裝TF,要求python版本號必須為3.5.x or 3.6.x,并且必須選擇為x64平臺的。
必須安裝Microsoft Visual C++ 2015 Redistributable Update 3,否則會執行失敗,報錯內容稍后提到(missing MSVCP140.dll)。
下載鏈接:
VC++安裝包下載:https://www.microsoft.com/en-us/download/details.aspx?id=53587
python:https://www.python.org/downloads/release/python-362/
安裝Bazel:https://docs.bazel.build/versions/master/install-windows.html
安裝Chocolatey:https://chocolatey.org/install
配置本地環境
1.VC++安裝包下載:
https://www.microsoft.com/en-us/download/details.aspx?id=53587
2.安裝python 3.6.x,
https://www.python.org/downloads/release/python-362/
3.安裝Cuda和CuDNN
谷歌提供了CPU和GPU版本的TensorFlow,使用GPU版本的TensorFlow進行訓練需要NVIDIA顯卡,并安裝Cuda和CnDNN,如果使用CPU版本的,可跳過這一步。
CUDA安裝:https://developer.nvidia.com/cuda-downloads
按照提示直接安裝即可。
CuDNN安裝:https://developer.nvidia.com/cudnn
這一步需要注冊一個賬號,并填寫一個問卷,完成后即可下載。CuDNN下載后解壓,添加 [yourPath]\cuda 和[yourPath]\cuda\bin 到環境變量 并按照如下操作:
[yourPath]\cuda\bin\cudnn64_5.dll —> (拷貝至)
[yourPath]\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\bin
[yourPath]\cuda\include\cudnn.h —> (拷貝至)
[yourPath]\NVIDIA GPU Computing Toolkit\CUDA\v8.0\include
[yourPath]\cuda\lib\x64\cudnn.lib —>(拷貝至)
[yourPath]\NVIDIA GPU Computing Toolkit\CUDA\v8.0\lib\x64
4.查看CUDA版本
在命令提示符中查看CUDA8的版本
C:\Users\Administrator.chenbo-ovr097b6>nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2016 NVIDIA Corporation
Built on Mon_Jan__9_17:32:33_CST_2017
Cuda compilation tools, release 8.0, V8.0.60
5.查看GPU設備信息
運行deviceQuery.exe,查看GPU設備信息
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\extras\demo_suite>device
Query.exe
deviceQuery.exe Starting...
CUDA Device Query (Runtime API) version (CUDART static linking)
Detected 1 CUDA Capable device(s)
Device 0: "Tesla M60"
CUDA Driver Version / Runtime Version? ? ? ? ? 9.0 / 8.0
CUDA Capability Major/Minor version number:? ? 5.2
Total amount of global memory:? ? ? ? ? ? ? ? 8108 MBytes (8501460992 bytes)
(16) Multiprocessors, (128) CUDA Cores/MP:? ? 2048 CUDA Cores
GPU Max Clock rate:? ? ? ? ? ? ? ? ? ? ? ? ? ? 1178 MHz (1.18 GHz)
Memory Clock rate:? ? ? ? ? ? ? ? ? ? ? ? ? ? 2505 Mhz
Memory Bus Width:? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 256-bit
L2 Cache Size:? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 2097152 bytes
Maximum Texture Dimension Size (x,y,z)? ? ? ? 1D=(65536), 2D=(65536, 65536),3D=(4096, 4096, 4096)
Maximum Layered 1D Texture Size, (num) layers? 1D=(16384), 2048 layers
Maximum Layered 2D Texture Size, (num) layers? 2D=(16384, 16384), 2048 layers
Total amount of constant memory:? ? ? ? ? ? ? 65536 bytes
Total amount of shared memory per block:? ? ? 49152 bytes
Total number of registers available per block: 65536
Warp size:? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 32
Maximum number of threads per multiprocessor:? 2048
Maximum number of threads per block:? ? ? ? ? 1024
Max dimension size of a thread block (x,y,z): (1024, 1024, 64)
Max dimension size of a grid size? ? (x,y,z): (2147483647, 65535, 65535)
Maximum memory pitch:? ? ? ? ? ? ? ? ? ? ? ? ? 2147483647 bytes
Texture alignment:? ? ? ? ? ? ? ? ? ? ? ? ? ? 512 bytes
Concurrent copy and kernel execution:? ? ? ? ? Yes with 2 copy engine(s)
Run time limit on kernels:? ? ? ? ? ? ? ? ? ? No
Integrated GPU sharing Host Memory:? ? ? ? ? ? No
Support host page-locked memory mapping:? ? ? Yes
Alignment requirement for Surfaces:? ? ? ? ? ? Yes
Device has ECC support:? ? ? ? ? ? ? ? ? ? ? ? Disabled
CUDA Device Driver Mode (TCC or WDDM):? ? ? ? TCC (Tesla Compute Cluster Driver)
Device supports Unified Addressing (UVA):? ? ? Yes
Device PCI Domain ID / Bus ID / location ID:? 0 / 0 / 21
Compute Mode:
< Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) >
deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 9.0, CUDA Runtime Version = 8.0, NumDevs = 1, Device0 = Tesla M60
Result = PASS
6.通過pip安裝TensorFlow
6.1安裝過程
pip是Python包管理工具,可以很方便的安裝一些軟件。我們在安裝Python的時候已經自動安裝了pip,現在可以直接在CMD中執行以下命令安裝TensorFlow。
CPU版本: pip install tensorflow
GPU版本: pip install tensorflow-gpu
注意:安裝python新版本后,可能會不帶pip因此需要先安裝pip,然后再安裝tensorflow
pip安裝方法:
python -m ensurepip? //安裝pip
python -m pip install tensorflow //安裝TF for CPU框架
python -m pip install tensorflow-gpu //安裝TF for GPU框架
6.2驗證
python
>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session() //看到GPU顯存信息
>>> print(sess.run(hello))
7 通過Anaconda安裝TensorFlow
7.1 安裝Anaconda
下載Anaconda中最新版本:https://www.anaconda.com/download/
7.2 打開conda客戶端,構建conda環境
C:> conda create -n tensorflow python=3.6
7.3 激活conda環境
C:> activate tensorflow
7.4 安裝框架
(tensorflow)C:> pip install --ignore-installed --upgrade tensorflow //安裝TF for CPU框架
(tensorflow)C:> pip install --ignore-installed --upgrade tensorflow-gpu //安裝TF for GPU框架
7.5 conda環境中驗證
python
>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session() //看到GPU顯存信息
>>> print(sess.run(hello))
8.完成