Cmake 安装 Caffe

  1. 首先修改Cmake里面的参数(GPU, CPU,MatLab,Python等);

  2. 修改 cmake/Dependencies.cmake 中的配置(BLAS之类的);

  3. Cmake:
    cd caffe && mkdir build && cd build
    cmake .. -DBUILD_SHARED_LIB=ON

    确保所有的error和warning都没有。
    
  4. 编译和安装:

     cmake . -DCMAKE_BUILD_TYPE=Debug     # 跳转到Debug模式下
     make -j 4 && make install           # -j 后面是CPU的核数,开启后编译速度会快很多
     cmake . -DCMAKE_BUILD_TYPE=Release   # 跳转到Release模式下
     make -j 4 && make install
    
  5. Debug和Release下生成的可执行文件不会相互覆盖,Debug下都会有-d的后缀。

Caffe单个文件编译

  1. 即是编译自己写的程序,同时使用Caffe的接口。同样,在我们调试和改进算法的时候也会用到。

  2. 如果按照上述用Cmake安装Caffe就比较简单,直接写好CmakeList.txt,然后cmake . && make 就可以了。

    CmakeList.txt:

    cmake_minimum_required(VERSION 3.0)

    find_package(Caffe)
    include_directories(${Caffe_INCLUDE_DIRS})
    add_definitions(${Caffe_DEFINITIONS})

    add_executable(yourApplication main.cpp)
    target_link_libraries(yourApplication ${Caffe_LIBRARIES})

如果直接用官方Makefile安装的可参阅[2]

/home/think/Documents/deeplearning/caffe-master/src
/usr/local/include
/usr/include
/home/think/Documents/deeplearning/caffe-master/build/include
/usr/local/cuda/include
/usr/local/include/opencv/
opt/OpenBLAS/include
/home/think/Documents/deeplearning/caffe-master/include

参考:
[1] https://github.com/BVLC/caffe/pull/1667
[2] http://caffe.berkeleyvision.org/installation.html
[3] http://hahack.com/codes/cmake/#安装和测试