Requirements
- Visual Studio 2013 or 2015
- Technically only the VS C/C++ compiler is required (cl.exe)
- CMake 3.4 or higher (Visual Studio and Ninja generators are supported)
Optional Dependencies
- Python for the pycaffe interface. Anaconda Python 2.7 or 3.5 x64 (or Miniconda)
- Matlab for the matcaffe interface.
- CUDA 7.5 or 8.0 (use CUDA 8 if using Visual Studio 2015)
- cuDNN v5
We assume that cmake.exe and python.exe are on your PATH.
我的安裝環境爲VS 2015、CMake 3.4.3、Anaconda Python 3.5.2、CUDA 8.0、cuDNN v5
Anaconda和Python的版本對應關係及下載地址可以從這裏找到,Anaconda Python
C:\Projects> git clone https://github.com/BVLC/caffe.git
C:\Projects> cd caffe
C:\Projects\caffe> git checkout windows
:: Edit any of the options inside build_win.cmd to suit your needs
C:\Projects\caffe> scripts\build_win.cmd
- 1
- 2
- 3
- 4
- 5
我這裏使用的是git bash,相應的安裝、使用教程可以從這裏找到,GitBash
轉存失敗重新上傳取消
編譯
而後編輯在caffe\scripts路徑下的build_win.cmd文件。
- 如果用CUDA,就SET CPU_ONLY=0
- PYTHON_VERSION設置自己需要的2或3
- SET WITH_NINJA=0
- 在倒數第二行加入CUDA路徑
-DCUDNN_ROOT=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0 ^
- 1
編譯前請刪除,如下文件
caffe\scripts\build路徑下的CMakeCache.txt文件
- 1
若出現如下問題,請首先給VS安裝C++組件
–The C compiler identification is unknown
–The CXX compiler identification is unknown
安裝完成C++組件後,再次運行build_win.cmd,開始下載
轉存失敗重新上傳取消
如有提示,找不到pthread.h,這是由於這個庫是LINUX、UNIX的VS有的庫,而Windows沒有,可以參照這個博客進行安裝,VS2015配置pthread.h
重新build,經過半個多小時,超多的warning,還是build成功了
轉存失敗重新上傳取消
那個DCUDNN_ROOT的問題,其實是這樣的。
在build_win.cmd裏,如果CUDA設置了環境變量,且cuDNN拷進了CUDA,就不需要再指定路徑了。
如果CUDA沒設置環境變量,就需要指定路徑。
我這裏是寫多餘了。
測試
進入/caffe/python路徑,打開python,測試import caffe成功
轉存失敗重新上傳取消
將/caffe/python/caffe文件夾拷貝到\Anaconda3\Lib\site-packages目錄下,這樣直接打開系統默認的Anaconda的Python也可以import caffe了。
用VS2015打開/caffe/scripts/caffe目錄下的caffe.sln解決方案
轉存失敗重新上傳取消
對整個解決方案進行Build操作。
等編譯完成後,在如下路徑會產生caffe.exe文件
C:\Documents\Caffe\caffe\scripts\build\tools\Release
- 1
事實上不編譯這個項目,也會有這個文件,之前的build_win.cmd已經完成了這一步編譯…
將路徑加入系統變量path,然後在cmd測試。
path='C:\Documents\Caffe\caffe\scripts\build\tools\Release'
cmd
輸入
caffe.exe -version
輸出
caffe.exe version 1.0.0