最近准备入坑caffe,操作系统是windows,记录下安过程,基本上就是按照github上的的安装步骤来的。

下载代码

caffe: a fast open framework for deep learning
然后chackout 到windows分支
(不推荐Microsoft的caffe,因为好久没更新了)

依赖项

VS2013,CMake,ptython(可选,推荐安装),matlab(可选),cuda,cudnn(使用cuda加速)

安装python

这里推荐使用anaconda,并且推荐使用python2.7版本的anaconda,因为python3和VS2013会出现问题。安装完成之后将python的路径加到系统的path中。

安装python之后,下载caffe使用到的包:

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
安装matlab

这一步是可选的。

下载cudnn

To use cuDNN the easiest way is to copy the content of the cuda folder into your CUDA toolkit installation directory. For example if you installed CUDA 8.0 and downloaded cudnn-8.0-windows10-x64-v5.1.zip you should copy the content of the cuda directory to C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0。

基本就是将cudnn的文件夹拷贝到cuda对应的文件夹中。

修改批处理文件
mingw的冲突

由于mingw中有gcc,会使得CMake检测到,然后优先使用这个编译器,所以我们如果有mingw,需要指定编译器,让CMake使用VS的编译器,只需要在build_win.cmd中的加入下面两行:

    :: add path for cl.exe
    set CMAKE_C_COMPILER="C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin/cl.exe"
    set CMAKE_CXX_COMPILER="C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin/cl.exe"

用于指定CMake使用的C++编译器。

其他路径和参数问题
::12表示使用VS2013
if NOT DEFINED MSVC_VERSION set MSVC_VERSION=12
::指定使用的python版本
if NOT DEFINED PYTHON_VERSION set PYTHON_VERSION=2.7
::指定anaconda的路径
set CONDA_ROOT=E:\software\Anaconda3
编译与demo

准备好依赖项,修改好路径,然后运行build_win.cmd就可以编译caffe 了。

demo可以参考:Training LeNet on MNIST with Caffe,需要注意的是,批处理在win下使用powershell(后缀为ps1),里面还需要修改caffe build的路径,而且windows默认是不能运行powershell文件的,需要改一下权限。

踩的坑
  1. VS2013和python 3.6的组合会出现以下error:
 Could not find url for MSVC version = 1800 and Python version = 3.5

参考caffe的issue:Cmake could not find url for MSVC version #5675

Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐