GitHub Windows版Caffe分支 Windows Caffe
安装环境
- Visual Studio 2015
Visual Studio Professional 2015 (x86 and x64) - DVD (Chinese-Simplified) - CMake 3.4 或更高
cmake-3.9.1-win64-x64.msi - Python 3.5 Anaconda x64
Anaconda3-4.2.0-Windows-x86_64.exe - CUDA 8.0
CUDA下载 - cuDNN v5.1
cuDNN 下载 需要注册
需要使用Tensorflow最新版本需要安装cuDNN v6 - MATLAB
需要使用Matconvnet,在CUDA8.0下,需要安装MATLAB2017a s8sh
cuDNN安装
- 安装CUDA
- 下载cuDNN并解压压缩包
- 将解压后的文件夹
cuda
下的文件分别复制到CUDA安装目录
cuDNN目录 | CUDA安装目录 |
---|---|
cuda\bin |
C:\Program Files\NVIDIA GPU Computing Tookit\CUDA\v8.0\bin |
cuda\include |
C:\Program Files\NVIDIA GPU Computing Tookit\CUDA\v8.0\include |
cuda\lib\x64 |
C:\Program Files\NVIDIA GPU Computing Tookit\CUDA\v8.0\lib\x64 |
安装Caffe
- D盘新建目录
CaffeBuild
- 打开cmd(命令提示符)切换到
CaffeBuild
目录
> d:
> cd CaffeBuild
- 下载Caffe
D:\CaffeBuild> git clone https://github.com/BVLC/caffe.git
D:\CaffeBuild> cd caffe
D:\CaffeBuild> git checkout windows
- 修改配置
在D:\CaffeBuild\caffe\scripts
下修改build_win.cmd
文件,使用Sublime打开
第8,9,14行
:: Default values
if DEFINED APPVEYOR (
echo Setting Appveyor defaults
if NOT DEFINED MSVC_VERSION set MSVC_VERSION=14
if NOT DEFINED WITH_NINJA set WITH_NINJA=0
if NOT DEFINED CPU_ONLY set CPU_ONLY=0
if NOT DEFINED CUDA_ARCH_NAME set CUDA_ARCH_NAME=Auto
if NOT DEFINED CMAKE_CONFIG set CMAKE_CONFIG=Release
if NOT DEFINED USE_NCCL set USE_NCCL=0
if NOT DEFINED CMAKE_BUILD_SHARED_LIBS set CMAKE_BUILD_SHARED_LIBS=0
if NOT DEFINED PYTHON_VERSION set PYTHON_VERSION=3
if NOT DEFINED BUILD_PYTHON set BUILD_PYTHON=1
if NOT DEFINED BUILD_PYTHON_LAYER set BUILD_PYTHON_LAYER=1
if NOT DEFINED BUILD_MATLAB set BUILD_MATLAB=1
if NOT DEFINED PYTHON_EXE set PYTHON_EXE=python
if NOT DEFINED RUN_TESTS set RUN_TESTS=1
if NOT DEFINED RUN_LINT set RUN_LINT=1
if NOT DEFINED RUN_INSTALL set RUN_INSTALL=1
第29行
:: Set python 3.5 with conda as the default python
if !PYTHON_VERSION! EQU 3 (
set CONDA_ROOT=D:\Anaconda3
)
第74行
:: Change to 1 to use Ninja generator (builds much faster)
if NOT DEFINED WITH_NINJA set WITH_NINJA=0
第87行
:: Change to 3 if using python 3.5 (only 2.7 and 3.5 are supported)
if NOT DEFINED PYTHON_VERSION set PYTHON_VERSION=3
第91行
:: Change these options for your needs.
if NOT DEFINED BUILD_PYTHON set BUILD_PYTHON=1
if NOT DEFINED BUILD_PYTHON_LAYER set BUILD_PYTHON_LAYER=1
if NOT DEFINED BUILD_MATLAB set BUILD_MATLAB=1
第167行添加
:: Configure using cmake and using the caffe-builder dependencies
:: Add -DCUDNN_ROOT=C:/Projects/caffe/cudnn-8.0-windows10-x64-v5.1/cuda ^
:: below to use cuDNN
cmake -G"!CMAKE_GENERATOR!" ^
-DBLAS=Open ^
-DCMAKE_BUILD_TYPE:STRING=%CMAKE_CONFIG% ^
-DBUILD_SHARED_LIBS:BOOL=%CMAKE_BUILD_SHARED_LIBS% ^
-DBUILD_python:BOOL=%BUILD_PYTHON% ^
-DBUILD_python_layer:BOOL=%BUILD_PYTHON_LAYER% ^
-DBUILD_matlab:BOOL=%BUILD_MATLAB% ^
-DCUDNN_ROOT=C:\Program Files\NVIDIA GPU Computiong Toolkit\CUDA\v8.0 ^
-DCPU_ONLY:BOOL=%CPU_ONLY% ^
-DCOPY_PREREQUISITES:BOOL=1 ^
-DINSTALL_PREREQUISITES:BOOL=1 ^
-DUSE_NCCL:BOOL=!USE_NCCL! ^
-DCUDA_ARCH_NAME:STRING=%CUDA_ARCH_NAME% ^
"%~dp0\.."
- 执行脚本
D:\CaffeBuild\caffe> scripts\build_win.cmd
耐心等待,希望别报错:)
下载依赖包可能因为网络原因会失败
网盘下载并放到下面这个目录下,其中users后面的路径改成你电脑的用户名
C:\Users\shuai\.caffe\dependencies\download
这个依赖包只适合这个环境,其他环境需要搞定网络后重新运行脚本
#报错
'"C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\..\..\VC\vcvarsall.bat"' 不是内部或外部命令,也不是 可运行的程序
或批处理文件。
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
CMake Error at CMakeLists.txt:18 (project):
No CMAKE_C_COMPILER could be found.
CMake Error at CMakeLists.txt:18 (project):
No CMAKE_CXX_COMPILER could be found.
-- Configuring incomplete, errors occurred!
See also "E:/CaffeBuild/caffe/build/CMakeFiles/CMakeOutput.log".
See also "E:/CaffeBuild/caffe/build/CMakeFiles/CMakeError.log".
ERROR: Configure failed
解决方法:打开VS2015安装程序,选择修改,勾选编程语言下的Visual C++
装了两次都出现下面这个错误
#报错
CMake Error at cmake/Utils.cmake:69 (string):
string sub-command STRIP requires two arguments.
解决方法:修改caffe\cmake下Utils.cmake,第69行加引号
# Function merging lists of compiler flags to single string.
# Usage:
# caffe_merge_flag_lists(out_variable [] [] ...)
function(caffe_merge_flag_lists out_var)
set(__result "")
foreach(__list ${ARGN})
foreach(__flag ${${__list}})
string(STRIP ${__flag} __flag)
set(__result "${__result} ${__flag}")
endforeach()
endforeach()
string(STRIP "${__result}" __result)
set(${out_var} ${__result} PARENT_SCOPE)
endfunction()
如果安装成功则在caffe\build\tools\Release
下有可执行文件
Python接口
打开Anaconda下的Anaconda Prompt
conda config --add channels conda-forge
conda config --add channels willyd
conda install --yes cmake ninja numpy scipy protobuf==3.1.0 six scikit-image pyyaml pydotplus graphviz
E:\CaffeBuild\caffe\python下caffe
文件夹复制到E:\Anaconda3\Lib\site-packages
下
在cmd中输入python
,执行import caffe
,若没有报错,则Python接口成功配置
MATLAB接口
在E:\caffeBuild\caffe\matlab
目录下MATLAB中运行>> caffe.run_tests()
把E:\CaffeBuild\caffe\matlab\+caffe\private\Release
下的caffe_mexw64
复制到E:\CaffeBuild\caffe\matlab\+caffe\private
下
修改matlab+caffe\Net.m第72行
function delete (self)
if self.isvalid
caffe_('delete_net', self.hNet_self);
end
end
下载模型,cmd在caffe根目录下执行
python scripts\download_model_binary.py models\bvlc_reference_caffenet
打开MATLAB,打开E:\CaffeBuild\caffe\matlab\demo\classification_demo.m
命令行窗口执行
im = imread('E:\CaffeBuild\caffe\examples\images\cat.jpg');
执行classification_demo.m
在MATLAB命令窗口执行help caffe
,如果不报错,则MATLAB接口配置成功