文章目录
  1. 1. Caffe
  2. 2. 在windows上安装caffe

Caffe


Caffe is a deep learning framework made with expression, speed, and modularity in mind. It is developed by the Berkeley Vision and Learning Center (BVLC) and by community contributors. Yangqing Jia created the project during his PhD at UC Berkeley. Caffe is released under the BSD 2-Clause license.
see http://caffe.berkeleyvision.org

在windows上安装caffe

项目地址:https://github.com/BVLC/caffe/tree/windows

以下安装步骤安装的是windows下的matlab版caffe,只使用cpu

  1. 预先准备好环境,需求cmakeninja generator(下载win版解压后的文件的目录加入path环境变量中), matlab(可使用R2016b版本), visual c++ build tools 或安装visual studio 2013/2015(用其中的cl编译器,mingw gcc编译可能出现问题)。 如果安装pycaffe,则需要安装Anaconda Python 2.7 or 3.5 x64 (or Miniconda),然后安装所需工具(见项目readme.md)

  2. 打开控制台,下载项目并切换到windows分支(假设在C:\Projects目录下下载caffe)

    1
    2
    3
    C:\Projects> git clone https://github.com/BVLC/caffe.git
    C:\Projects> cd caffe
    C:\Projects\caffe> git checkout windows
  3. 修改scripts\build_win.cmd文件,部分参考如下

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    :: Change the settings here to match your setup
    :: Change MSVC_VERSION to 12 to use VS 2013
    if NOT DEFINED MSVC_VERSION set MSVC_VERSION=14
    :: Change to 1 to use Ninja generator (builds much faster)
    if NOT DEFINED WITH_NINJA set WITH_NINJA=1
    :: Change to 1 to build caffe without CUDA support
    if NOT DEFINED CPU_ONLY set CPU_ONLY=1
    :: Change to Debug to build Debug. This is only relevant for the Ninja generator the Visual Studio generator will generate both Debug and Release configs
    if NOT DEFINED CMAKE_CONFIG set CMAKE_CONFIG=Release
    :: Set to 1 to use NCCL
    if NOT DEFINED USE_NCCL set USE_NCCL=0
    :: Change to 1 to build a caffe.dll
    if NOT DEFINED CMAKE_BUILD_SHARED_LIBS set CMAKE_BUILD_SHARED_LIBS=0
    :: Change to 3 if using python 3.5 (only 2.7 and 3.5 are supported)
    if NOT DEFINED PYTHON_VERSION set PYTHON_VERSION=2
    :: Change these options for your needs.
    if NOT DEFINED BUILD_PYTHON set BUILD_PYTHON=0
    if NOT DEFINED BUILD_PYTHON_LAYER set BUILD_PYTHON_LAYER=0
    if NOT DEFINED BUILD_MATLAB set BUILD_MATLAB=1
    :: If python is on your path leave this alone
    if NOT DEFINED PYTHON_EXE set PYTHON_EXE=python
    :: Run the tests
    if NOT DEFINED RUN_TESTS set RUN_TESTS=0
    :: Run lint
    if NOT DEFINED RUN_LINT set RUN_LINT=0
    :: Build the install target
    if NOT DEFINED RUN_INSTALL set RUN_INSTALL=1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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% ^
-DBUILD_python=0 ^
-DBUILD_python_layer=0 ^
-DCPU_ONLY:BOOL=%CPU_ONLY% ^
-DCOPY_PREREQUISITES:BOOL=1 ^
-DINSTALL_PREREQUISITES:BOOL=1 ^
-DUSE_NCCL:BOOL=!USE_NCCL! ^
-DCPU_ONLY=1 ^
-DBUILD_matlab=ON ^
"%~dp0\.."
  1. (可选)如果网络状况不好,则需手动下载依赖文件libraries_v140_x64_py27_1.0.1.tar.bz2,然后在caffe根目录(C:\Projects\caffe)新建文件夹build,并放入该文件

  2. 在控制台执行安装

    1
    C:\Projects\caffe> scripts\build_win.cmd

如无意外,将在build文件夹下生成ninja项目及编译后的文件,将其中的C:\project\caffe\build\install\bin加入path环境变量,将C:\project\caffe\build\Matlab下的caffe.exp和caffe.lib复制到C:\project\caffe\matlab+caffe\private中(编译后该目录同时生成了caffe_.mexw64文件)

  1. 打开matlab,将当前工作目录改为C:\project\caffe\matlab,并执行
    1
    >> caffe.run_tests()

如能显示结果并无报错,则安装成功,如报错,则重启一次matlab再执行,如仍然有错,可以到https://github.com/BVLC/caffe/issues查看有无类似问题。

文章目录
  1. 1. Caffe
  2. 2. 在windows上安装caffe