一. 安裝cuda8.0
1)先去官網下載cuda8.0 https://developer.nvidia.com/cuda-toolkit
2)下載完之后進行安裝,安裝時間有點長,請耐心等待,默認是安裝在c盤目錄下
安裝完后會生成兩個系統變量:
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 命令,如圖所示

表示cuda安裝成功
4)進入sdk實例安裝目錄
C:\ProgramData\NVIDIA Corporation\CUDA Samples\v8.0
點擊Samples_vs2013.sln文件打開vs2013執行
運行Samples_vs2013.sln文件就會出現如圖所示

表明測試成功
或者試試
nvcc -V
二. 下載安裝CAFFE
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的加載失敗錯誤項。
如果某個包下載不了。。。那就參考這個吧
在項目中打開 工具->NuGet程序包管理器->控制台,並輸入命令:Install-Package fluentnhibernate ,進行安裝。
Install-Package boost_regex-vc120 -version 1.59 -Source C:\Users\Administrator\AppData\Local\NuGet\Cache\
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)
三. 安裝Tensorflow
之前安裝過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
四. 安裝keras
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" }
五. 安裝PyTorch
安裝官方建議:
conda install pytorch torchvision -c pytorch
但往往。。。安裝pythorch的時候下載慢的一比,因此可以考慮離線安裝
https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/win-64/
安裝完以后可以驗證下
import torch import torchvision print(torch.__version__) print(torch.cuda.is_available())
簡單練習






