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編譯:(待續)


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章