ubuntu16.04 从源码编译安装caffe(纯CPU版)

需要做caffe在嵌入式的移植,决定先在X86上理清所有依赖包关系,再做交叉编译,由于目的是用在嵌入式,暂不支持GPU。

1.boost

官网:http://www.boost.org/

Caffe 中主要使用了Boost 的智能指针,新版v1.66.0支持C++11。

pycaffe使用了Boost Python 实现c/c++和Python的链接,方便Python调用c/c++模块。

tar jxvf boost_1_66_0.tar.bz2 
cd boost_1_66_0/
1) 使用--show-libraries查看所有支持单独编译的庫库:
./bootstrap.sh –show-libraries
2) 使用 --without-libraries=, , , 逗号隔开去掉不需要编译的库,或者使用—with-libraries添加必要支持的库,--prefix=/../ 指定编译后的安装路径, 也可以在jam文件配置;
./bootstrap.sh –with-libraries=system,thread,filesystem

3) 生成b2和bjam,和project-config.jam,修改该文件,配置相关路径:


./bjam
./bjam installh1 { margin-bottom: 0.21cm; }h1.western { font-family: "Liberation Sans", sans-serif; font-size: 18pt; }h1.cjk { font-family: "Noto Sans CJK SC Regular"; font-size: 18pt; }h1.ctl { font-family: "Noto Sans CJK SC Regular"; font-size: 18pt; }p { margin-bottom: 0.25cm; line-height: 120%; }a:link { }code.ctl { font-family: "Liberation Mono", monospace; }


2.opencv

参考链接:https://blog.csdn.net/luteresa/article/details/79916064


3.protobuf

google开发的一种可以实现内存和非易失存储介质(如硬盘)交换的协议接口。使用protobuf可以跨语言(c++/java/python)传递相同的数据结构。
仓库:https://github.com/google/protobuf.git
C++ Installation – Unix

To build protobuf from source, the following tools are needed:
autoconf
automake
libtool
curl (used to download gmock)
make
g++
unzip
On Ubuntu, you can install them with:

$ sudo apt-get install autoconf automake libtool curl make g++ unzip
./autogen.sh
 ./configure  --prefix=/home/leon/caffe_install/

$ make
$ make install


4.GFLAGS

GFLAGS在Caffe 中主要起到命令行参数解析作用,与protobuf类似,只是输入源不同。

仓库:https://github.com/gflags/gflags.git

mkdir build;cd build/
cmake ..
ccmake ..
修改两行:BUILD_SHARED_LIBS ON
CMAKE_INSTALL_PREFIX /home/leon/caffe_install

按c,g,生成Makefle。


Make
make install

5.GLOG

GLOG在Caffe 中主要起到记录日志的作用,便于开发者查看Caffe训练中产生的中间输出,并根据这些信息决定如何调整参数来控制收敛。GLOG 的使用方法参考tools/caffe.cpp
仓库:https://github.com/google/glog.git


glog依赖gflags库:
./autogen.sh
./configure --prefix=/home/leon/caffe_install/  --with-gflags=/home/leon/caffe_install/

make
make install

6.HDF5

HDF(Hierarchical Data File)美国国家高级计算应用中心(NCSA)为满足各种领域研究需求而研制的一种能高效存储和分发科学数据的新型数据格式。可以存储不同类型的图像和数码数据的文件,并且可以在不同类型的机器上传输,同时还有统一处理这种格式的函数库。Caffe 训练模型可以选择保存为HDF5格式或者ProtoBuffer(默认)格式。
官网:https://www.hdfgroup.org/downloads/hdf5/source-code/
./configure –prefix=/home/leon/caffe_install/
make
make install

7.BLAS

最常用的BLAS 库有 ATLAS,Intel MKL,OpenBLAS。ATLAS 是免费开源的,也
是 Caffe 的默认选择。Intel MKL 是商业性质的,针对 Intel 的 CPU 专门做了优化的
BLAS 库,可以选择使用免费试用以及学生 licenses。OpenBLAS 是免费开源的,针对
并行做了优化的 BLAS 库。
在GPU端的数值计算则由相应的cuBLAS完成,其API接口与OpenBLAS类似。

caffe可以选中任何一种,在Makefile.config文件修改”BLAS:=”一行
# BLAS choice:
# atlas for ATLAS (default)
# mkl for MKL
# open for OpenBlas                                                                           
BLAS := open

仓库: git clone https://github.com/xianyi/OpenBLAS.git  (最新为OpenBLAS 0.2.20 version)

cd OpenBLAS/

make

make PREFIX=/home/leon/caffe_install/   install


8.Snappy

Snappy是一个用来压缩的C++库,比zlib更快,但文件相对更大;
仓库:https://github.com/google/snappy
修改CMakeLists.txt,打开动态库选项
option(BUILD_SHARED_LIBS "Build shared libraries(DLLs)." ON)

mkdir build
cd build
cmake -D CMAKE_INSTALL_PREFIX=/home/leon/caffe_install  ..
make
make install

9.LMDB/LEVELDB

LMDB在caffe中作用主要是提供数据管理,将各色原始数据(JPEG图片,二进制数据)转换为统一的Key-Value存储,便于Caffe 的DataLayer获取这些数据。
LEVELDB库是Caffe中早期版本使用的数据存储方式,由google开发,目前大部分应用都已经使用LMDB替代了LEVELDB,但是了兼容,仍然需要将这个依赖库编译到Caffe中。
LMDB:
仓库:https://github.com/LMDB/lmdb.git

修改Makefile :
#prefix    = /usr/local
prefix    = /home/leon/arm_install/

make
make install

LEVELDB:

仓库:https://github.com/google/leveldb.git

make
cp -r include/leveldb/  /home/leon/caffe_install/include/
cp libleveldb.so* /home/leon/caffe_install/lib/

所有库和头文件都已经安装在/home/leon/caffe_install/, 路径加入到环境变量中,准备工作就绪;

终于来到主咖caffe。


caffe编译:(待续)


猜你喜欢

转载自blog.csdn.net/luteresa/article/details/79932539