1 环境:win10,vs2013。
2 安装cuda和cudnn,(cuda和cudnn的版本一定要对应,且要与caffe版本对应,比如cuda7.5和cudnn5.1,我们可以在官网下载cuda后,根据版本在官网下载cudnn,因为caffe-master对应的事cudnnv4-v5的才行,所以不能下载9.0的)。
3 安装opencv(即使不安装,caffe项目在编译后,也生成了一些opencv库,但在运行faster-rcnn时不一定够用,我们最好选择安装)。我的安装路径是D:\opencv2.4,那么环境变量配置:系统变量path:
D:\opencv2.4\opencv\build\x64\v12\bin; D:\opencv2.4\opencv\build\x86\v12\bin;
在项目中也要进行相应的VC++1包含目录、2库目录、3链接器输入配置:
1. D:\Caffe\opencv\build\include
D:\Caffe\opencv\build\include\opencv
D:\Caffe\opencv\build\include\opencv2
2.D:\Caffe\opencv\build\x86\vc12\lib(2库目录好像可有可无)
D:\Caffe \opencv\build\x86\vc12\staticlib
3.opencv_calib3d2410.lib;opencv_contrib2410.lib;opencv_core2410.lib;opencv_features2d2410.lib;opencv_flann2410.lib;opencv_gpu2410.lib;opencv_highgui2410.lib;opencv_imgproc2410.lib;opencv_legacy2410.lib;opencv_ml2410.lib;opencv_objdetect2410.lib;opencv_ts2410.lib;opencv_video2410.lib;caffe.lib;libcaffe.lib;cudart.lib;cublas.lib;curand.lib;gflags.lib;libglog.lib;libopenblas.dll.a;libprotobuf.lib;leveldb.lib;lmdb.lib;hdf5.lib;hdf5_hl.lib;%(AdditionalDependencies)
4 安装Anaconda(我们安装对应python2.7的Anaconda版本),安装好以后注意配置环境变量,这个最好在安装的时候直接选择配置(如果不安装,环境配置虽然能编译通过,但程序在运行时会报异常)。环境配置如下:
成功后在CMD运行:
1 conda install --yes numpy scipy matplotlib scikit-image pip
2 pip install protobuf
5 下载Caffe原始项目。(https://github.com/Microsoft/caffe)
6 将caffe-master/windows/CommonSettings.props.example复制一份叫做caffe-master/windows/CommonSettings.prop。然后打开复制好的文件,根据我们的实际安装情况进行配置,是否使用的GPU,Anaconda的路径等。如下图所示。修改处:1版本号、2cudnn安装路径、3python支持路径(也就是Anaconda的安装路径)红色方框显示可以证明只能用cudnnv4或v5
7 打开caffe-master/windows/caffe.sln,项目选择released模式,修改libcaffe的C++常规设置,将警告视为错误选择否,(括号中的在步骤8之后进行:如果需要使用faster-rcnn,直接看下一步faster-rcnn配置的编译步骤,以免重复编译,如不需要,则直接开始生成解决方案,会出现Nuget还原管理界面,结束后会在caffe-master的同级目录下生成一个NugetPackages的目录,装的是各种依赖库。)
8 由于faster-rcnn中使用了roi-pooling-layer层,而微软版本编译时并未添加roi_pooling_layer,打开caffe-master\windows下的caffe.sln文件,将我们需要的头文件,cu文件和cpp文件手动加入到libcaffe对应的cu、inlcude、src文件夹的layer层中。添加完成后,编译整个项目。编译成功后,整个caffe就编译完成了。(时间比较长,则直接开始生成解决方案,会出现Nuget还原管理界面,结束后会在caffe-master的同级目录下生成一个NugetPackages的目录,装的是各种依赖库。)
9 新建faster-rcnn项目,在caffe-master/windows/下新建项目。
10 下载整理好的第三方依赖项faster_3rdparty,
链接:http://pan.baidu.com/s/1qYttnsS 密码:d0ud,将其解压到caffe-master/目录下,将faster_3rdparty/bin目录添加到系统环境变量中。
11.然后进行如下配置,下面给出我的配置目录,建立项目时根据自身安装目录,做相应修改,假设D:\Caffe\中安装的caffe-master、opencv修改如下:
c++包含目录:
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.5\include; D:\Caffe\caffe-master\faster_3rdparty\include;D:\Caffe\caffe-master\include;D:\Caffe\opencv\build\include\opencv2;D:\Caffe\opencv\build\include; D:\Caffe \opencv\build\include\opencv;$(IncludePath)
库链接目录:
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.5\lib\x64; D:\Caffe\caffe-master\faster_3rdparty\lib; D:\Caffe\caffe-master\Build\x64\Release; .D:\Caffe\opencv\build\x86\vc12\lib; D:\Caffe\opencv\build\x86\vc12\staticlib;$(LibraryPath)
附加依赖项:opencv_calib3d2410.lib;opencv_contrib2410.lib;opencv_core2410.lib;opencv_features2d2410.lib;opencv_flann2410.lib;opencv_gpu2410.lib;opencv_highgui2410.lib;opencv_imgproc2410.lib;opencv_legacy2410.lib;opencv_ml2410.lib;opencv_objdetect2410.lib;opencv_ts2410.lib;opencv_video2410.lib;caffe.lib;libcaffe.lib;cudart.lib;cublas.lib;curand.lib;gflags.lib;libglog.lib;libopenblas.dll.a;libprotobuf.lib;leveldb.lib;lmdb.lib;hdf5.lib;hdf5_hl.lib;%(AdditionalDependencies)
11 新建项目为启动项目,且只编译该项目,然后运行即可。若是存在处理异常,可以尝试注释掉对应代码。