Cmake 安装 Caffe
首先修改Cmake里面的参数(GPU, CPU,MatLab,Python等);
修改 cmake/Dependencies.cmake 中的配置(BLAS之类的);
Cmake:
cd caffe && mkdir build && cd build
cmake .. -DBUILD_SHARED_LIB=ON确保所有的error和warning都没有。
编译和安装:
cmake . -DCMAKE_BUILD_TYPE=Debug # 跳转到Debug模式下 make -j 4 && make install # -j 后面是CPU的核数,开启后编译速度会快很多 cmake . -DCMAKE_BUILD_TYPE=Release # 跳转到Release模式下 make -j 4 && make install
Debug和Release下生成的可执行文件不会相互覆盖,Debug下都会有-d的后缀。
Caffe单个文件编译
- 即是编译自己写的程序,同时使用Caffe的接口。同样,在我们调试和改进算法的时候也会用到。
如果按照上述用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/#%E5%AE%89%E8%A3%85%E5%92%8C%E6%B5%8B%E8%AF%95