1)先去官網下載cuda8.0 https://developer.nvidia.com/cuda-toolkithtml
2)下載完以後進行安裝,安裝時間有點長,請耐心等待,默認是安裝在c盤目錄下python
安裝完後會生成兩個系統變量:git
CUDA_PATH C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0 CUDA_PATH_V8_0 C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0
3)測試是否成功 : 進入cmd,輸入 nvcc -V 命令,如圖所示github
表示cuda安裝成功express
4)進入sdk實例安裝目錄apache
C:\ProgramData\NVIDIA Corporation\CUDA Samples\v8.0
點擊Samples_vs2013.sln文件打開vs2013執行 json
運行Samples_vs2013.sln文件就會出現如圖所示windows
代表測試成功api
或者試試app
nvcc -V
1)拷貝 .\windows\CommonSettings.props.example
到 .\windows\CommonSettings.props
默認狀況下Windows版本caffe須要 CUDA
和 cuDNN
庫,你也能夠在.\windows\CommonSettings.props
裏禁用他們。
默認狀況下matlab/Python支持被沒有開啓的,你也能夠經過修改 .\windows\CommonSettings.props
來啓用。
2)若是你不須要CUDA,你能夠安裝CPU_ONLY版本:編輯文件.\windows\CommonSettings.props
,設置CpuOnlyBuild
爲 true
,UseCuDNN
爲false
。
3)cuDNN V5 下載 (不使用能夠跳過)
解壓下載的zip文件到 %CUDA_PATH% (這個環境變量是由上一步安裝的CUDA設置的)。或者你也能夠解壓到任何位置, 而後再 .\windows\CommonSettings.props
裏設置 CuDnnPath
來指向解壓到的目錄。
你能夠修改.\windows\CommonSettings.props
文件,設置 UseCuDNN
爲 false
來禁用cuDNN。
https://developer.nvidia.com/rdp/cudnn-download
4)Python
爲了編譯Caffe Python封裝庫,須要.\windows\CommonSettings.props
文件,設置 PythonSupport
爲 true
。
下載 Anaconda2 64-bit Windows installer: Anaconda2 。
安裝完後咱們須要將.\windows\CommonSettings.props 中python PythonDir 改爲咱們本身的
接下來安裝 google.protoc
編譯python支持庫後,你還須要執行以下之一才能在python裏使用:
PythonPath
,值爲 <caffe_root>\Build\x64\Release\pycaffe
,或者<caffe_root>\Build\x64\Release\pycaffe\caffe
到 <python_root>\lib\site-packages
目錄注意:python 不存在debug庫
5).Matlab
編譯Matlab支持,修改.\windows\CommonSettings.props
文件,設置 MatlabSupport
爲true
,MatlabDir
爲 Matlab安裝根目錄。
</PropertyGroup> <PropertyGroup Condition="'$(MatlabSupport)'=='true'"> <MatlabDir>C:\Program Files\MATLAB\R2014a</MatlabDir> <LibraryPath>$(MatlabDir)\extern\lib\win64\microsoft;$(LibraryPath)</LibraryPath> <IncludePath>$(MatlabDir)\extern\include;$(MatlabDir);$(IncludePath)</IncludePath> </PropertyGroup>
注意:最近Microsoft 的github貌似更新了matcaffe中的caffe_.cpp文件,第十六行添加了對 gpu/mxGPUArray.h 的引用
修改matcaffe中的第十六行 #include"gpu/mxGPUArray.h" 中修改成
#include<toolbox/distcomp/gpu/extern/include/gpu/mxGPUArray.h>
編譯Matlab支持庫後,你還須要執行以下操做才能在matlab裏使用:
matcaffe
目錄到 Matlab 搜索路徑,<caffe_root>\Build\x64\Debug
到 系統環境變量 PATH(不必定須要)
6)打開 Caffe.sln 解決方案
第三方Caffe依賴庫被自動經過NuGet安裝:
右鍵工程-》管理NuGet程序包,還原全部的包。原始使用的opencv是2.4.10版本(我卸掉它使用opencv3.1). 全部包會下載到
C:\Users\Administrator\AppData\Local\NuGet\Cache
這裏是清單:
若是你將opencv改爲了3.1注意要刪除每一個項目文件下 *.vcxproj 裏有關opencv2.4.10的加載失敗錯誤項。
7)編譯
如今你能夠開始編譯工程文件了: .\windows\Caffe.sln
注意要先編譯 libcaffe, 同時編譯python時只能選Release
8)爲了之後使用方便,咱們將生成的exe路徑放入環境目錄path裏
C:\caffe-master2\Build\x64\Debug
9) 爲了使用caffe的sh腳本文件,咱們須要安裝 Git 和 wgetwin (將wget.exe放入C:\Windows\System32)
以前安裝過python2.7,但是爲了學習tensorflow,這裏要安裝下python3.5
1.首先,去下載地址(下載包含python3.5版本的Anaconda)
2. 安裝過程和anaconda2相似,可是,安裝的路徑要設置在anaconda2的envs文件夾下,另起名,我起名爲py3.
安裝過程的不一樣之處在下圖:
將環境變量修改了(安裝結束後再改回去),而後
conda install ipython
conda install jupyter
3.完成後,檢查是否安裝成功,首先,cmd輸入python,顯示的以前的python版本(以前默認的是python版本)
python -V
咱們想用3.5版本就須要激活,命令:
activate py3
4.安裝Tensorflow
pip install setuptools --ignore-installed
這是指定安裝tensorflow版本方式
pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/windows/gpu/tensorflow_gpu-1.2.1-cp36-cp36m-win_amd64.whl
這是利用conda安裝方式,這種方式須要將環境變量修改了(安裝結束後再改回去)
conda install -c https://conda.anaconda.org/jjhelmus tensorflow-gpu
這是官方建議的安裝方式,會安裝最新版
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple --upgrade tensorflow-gpu
由於不一樣的版本對應着不一樣的cudnn因此用腳本 tensorflow_self_check.py 檢查一遍
# Copyright 2015 The TensorFlow Authors. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # ============================================================================== """A script for testing that TensorFlow is installed correctly on Windows. The script will attempt to verify your TensorFlow installation, and print suggestions for how to fix your installation. """ import ctypes import imp import sys def main(): try: import tensorflow as tf print("TensorFlow successfully installed.") if tf.test.is_built_with_cuda(): print("The installed version of TensorFlow includes GPU support.") else: print("The installed version of TensorFlow does not include GPU support.") sys.exit(0) except ImportError: print("ERROR: Failed to import the TensorFlow module.") candidate_explanation = False python_version = sys.version_info.major, sys.version_info.minor print("\n- Python version is %d.%d." % python_version) if not (python_version == (3, 5) or python_version == (3, 6)): candidate_explanation = True print("- The official distribution of TensorFlow for Windows requires " "Python version 3.5 or 3.6.") try: _, pathname, _ = imp.find_module("tensorflow") print("\n- TensorFlow is installed at: %s" % pathname) except ImportError: candidate_explanation = False print(""" - No module named TensorFlow is installed in this Python environment. You may install it using the command `pip install tensorflow`.""") try: msvcp140 = ctypes.WinDLL("msvcp140.dll") except OSError: candidate_explanation = True print(""" - Could not load 'msvcp140.dll'. TensorFlow requires that this DLL be installed in a directory that is named in your %PATH% environment variable. You may install this DLL by downloading Microsoft Visual C++ 2015 Redistributable Update 3 from this URL: https://www.microsoft.com/en-us/download/details.aspx?id=53587""") try: cudart64_80 = ctypes.WinDLL("cudart64_80.dll") except OSError: candidate_explanation = True print(""" - Could not load 'cudart64_80.dll'. The GPU version of TensorFlow requires that this DLL be installed in a directory that is named in your %PATH% environment variable. Download and install CUDA 8.0 from this URL: https://developer.nvidia.com/cuda-toolkit""") try: nvcuda = ctypes.WinDLL("nvcuda.dll") except OSError: candidate_explanation = True print(""" - Could not load 'nvcuda.dll'. The GPU version of TensorFlow requires that this DLL be installed in a directory that is named in your %PATH% environment variable. Typically it is installed in 'C:\Windows\System32'. If it is not present, ensure that you have a CUDA-capable GPU with the correct driver installed.""") cudnn5_found = False try: cudnn5 = ctypes.WinDLL("cudnn64_5.dll") cudnn5_found = True except OSError: candidate_explanation = True print(""" - Could not load 'cudnn64_5.dll'. The GPU version of TensorFlow requires that this DLL be installed in a directory that is named in your %PATH% environment variable. Note that installing cuDNN is a separate step from installing CUDA, and it is often found in a different directory from the CUDA DLLs. You may install the necessary DLL by downloading cuDNN 5.1 from this URL: https://developer.nvidia.com/cudnn""") cudnn6_found = False try: cudnn = ctypes.WinDLL("cudnn64_6.dll") cudnn6_found = True except OSError: candidate_explanation = True if not cudnn5_found or not cudnn6_found: print() if not cudnn5_found and not cudnn6_found: print("- Could not find cuDNN.") elif not cudnn5_found: print("- Could not find cuDNN 5.1.") else: print("- Could not find cuDNN 6.") print(""" The GPU version of TensorFlow requires that the correct cuDNN DLL be installed in a directory that is named in your %PATH% environment variable. Note that installing cuDNN is a separate step from installing CUDA, and it is often found in a different directory from the CUDA DLLs. The correct version of cuDNN depends on your version of TensorFlow: * TensorFlow 1.2.1 or earlier requires cuDNN 5.1. ('cudnn64_5.dll') * TensorFlow 1.3 or later requires cuDNN 6. ('cudnn64_6.dll') You may install the necessary DLL by downloading cuDNN from this URL: https://developer.nvidia.com/cudnn""") if not candidate_explanation: print(""" - All required DLLs appear to be present. Please open an issue on the TensorFlow GitHub page: https://github.com/tensorflow/tensorflow/issues""") sys.exit(-1) if __name__ == "__main__": main()
測試
import tensorflow as tf h = tf.constant('Hello, Tensorflow!') s = tf.Session() print(s.run(h))
關閉3.5:
deactivate py3
pip install bcolz
若是安裝有問題,就下載安裝吧
pip install keras
安裝結束後在此新建
C:\Users\MyPC\.keras\keras.json
這個文件中能夠指定使用tensorflow仍是theano
{ "image_dim_ordering": "tf", "epsilon": 1e-07, "floatx": "float32", "image_data_format": "channels_last", "backend": "tensorflow" }
{ "image_dim_ordering": "th", "floatx": "float32", "epsilon": 1e-07, "backend": "theano", "image_data_format": "channels_last" }
安裝官方建議:
conda install pytorch -c pytorch
pip3 install torchvision
但每每。。。安裝pythorch的時候下載慢的一比,所以能夠考慮離線安裝
https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/win-64/
安裝完之後能夠驗證下
import torch import torchvision print(torch.__version__) print(torch.cuda.is_available())
簡單練習