Ubuntu14:cmake生成Makefile编译caffe过程(OpenBLAS/CPU only)

前端之家收集整理的这篇文章主要介绍了Ubuntu14:cmake生成Makefile编译caffe过程(OpenBLAS/CPU only)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

之前在CentOS6.5下成功完成了caffe的编译(参见《CentOS6.5编译Caffe过程记录(系统存在多个编译器)》),最近将操作系统平台换成了ubuntu14,网上找到的介绍ubuntu下编译caffe的文章都是直接修改Makfile.config和Makefile来完成编译的,caffe本身提供了用于生成 Makefile的cmake脚本,所以我还是希望尝试用cmake生成的Makefile来完成编译。
caffe原本应该就是在ubuntu下开发的,所以我本以为ubuntu下编译会很顺利,实际操作,还是踩到一些坑。
以下记录cmake方式编译caffe的过程(与CentOS6.5下还是有些不同)

编译环境准备

#!/bin/bash
sudo apt-get install libprotobuf-dev libprotobuf-compiler libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev 
sudo apt-get install libboost-all-dev   // 安装boost库
#sudo apt-get install libatlas-base-dev //BLAS如使用OpenBLAS,可不安装
sudo apt-get install libopenblas-dev    //BLAS如使用atlas,可不安装
sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev
sudo apt-get install python-numpy  // 安装numpy

编译caffe

#!/bin/bash
caffe_folder=caffe-master
if [ -d $caffe_folder ]
then 
    rm -fr $caffe_folder
fi
# 从 https://github.com/BVLC/caffe 下载Caffe源码 caffe-master.zip解压缩
unzip $caffe_folder.zip 
pushd $caffe_folder
# 执行cmake生成Makefile
mkdir build && cd build
#编译cpu版本,BLAS 使用OpenBLAS(速度更快些)
cmake -Dcpu_ONLY=ON -DBLAS=Open -DHDF5_HL_INCLUDE_DIR=/usr/include/hdf5/serial ..
# 开始编译并安装到build/install下 
# -j24 指定24线程执行
make install -j 24
cd ..
popd

说明:
-DHDF5_HL_INCLUDE_DIR=/usr/include/hdf5/serial用于手工指定HDF5_HL_INCLUDE_DIR位置,否则会编译会报错:

./include/caffe/util/hdf5.hpp:6:18: fatal error: hdf5.h: No such file or directory

cmake -Dcpu_ONLY=ON -DBLAS=Open -DHDF5_HL_INCLUDE_DIR=/usr/include/hdf5/serial .. 输出

-- The C compiler identification is GNU 5.4.0 -- The CXX compiler identification is GNU 5.4.0 -- Check for working C compiler: /usr/bin/cc -- Check for working C compiler: /usr/bin/cc -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Detecting C compile features -- Detecting C compile features - done -- Check for working CXX compiler: /usr/bin/c++ -- Check for working CXX compiler: /usr/bin/c++ -- works -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Detecting CXX compile features -- Detecting CXX compile features - done -- Looking for pthread.h -- Looking for pthread.h - found -- Looking for pthread_create -- Looking for pthread_create - not found -- Looking for pthread_create in pthreads -- Looking for pthread_create in pthreads - not found -- Looking for pthread_create in pthread -- Looking for pthread_create in pthread - found -- Found Threads: TRUE -- Boost version: 1.58.0 -- Found the following Boost libraries: -- system -- thread -- filesystem -- chrono -- date_time -- atomic -- Found GFlags: /usr/local/include -- Found gflags (include: /usr/local/include,library: /usr/local/lib/libgflags.a) -- Found Glog: /usr/local/include -- Found glog (include: /usr/local/include,library: /usr/local/lib/libglog.a) -- Found Protobuf: /usr/lib/x86_64-linux-gnu/libprotobuf.so;-lpthread (found version "2.6.1") -- Found PROTOBUF Compiler: /usr/bin/protoc -- HDF5: Using hdf5 compiler wrapper to determine C configuration -- HDF5: Using hdf5 compiler wrapper to determine CXX configuration -- Found HDF5: /usr/lib/x86_64-linux-gnu/libhdf5_cpp.so;/usr/lib/x86_64-linux-gnu/hdf5/serial/libhdf5.so;/usr/lib/x86_64-linux-gnu/libpthread.so;/usr/lib/x86_64-linux-gnu/libsz.so;/usr/lib/x86_64-linux-gnu/libz.so;/usr/lib/x86_64-linux-gnu/libdl.so;/usr/lib/x86_64-linux-gnu/libm.so (found version "1.8.16") found components: HL -- Found LMDB: /usr/include -- Found lmdb (include: /usr/include,library: /usr/lib/x86_64-linux-gnu/liblmdb.so) -- Found LevelDB: /usr/include -- Found LevelDB (include: /usr/include,library: /usr/lib/x86_64-linux-gnu/libleveldb.so) -- Found Snappy: /usr/include -- Found Snappy (include: /usr/include,library: /usr/lib/x86_64-linux-gnu/libsnappy.so) -- -- CUDA is disabled. Building without it... -- OpenCV found (/usr/share/OpenCV) -- Found OpenBLAS libraries: /usr/lib/libopenblas.so -- Found OpenBLAS include: /usr/include -- Found PythonInterp: /usr/bin/python2.7 (found suitable version "2.7.12",minimum required is "2.7") -- Found PythonLibs: /usr/lib/x86_64-linux-gnu/libpython2.7.so (found suitable version "2.7.12",minimum required is "2.7") -- Found NumPy: /usr/lib/python2.7/dist-packages/numpy/core/include (found suitable version "1.11.0",minimum required is "1.7.1") -- NumPy ver. 1.11.0 found (include: /usr/lib/python2.7/dist-packages/numpy/core/include) -- Boost version: 1.58.0 -- Found the following Boost libraries: -- python -- Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE) -- Could NOT find Git (missing: GIT_EXECUTABLE) -- -- ******************* Caffe Configuration Summary ******************* -- General: -- Version : 1.0.0-rc3 -- Git : unknown -- System : Linux -- C++ compiler : /usr/bin/c++ -- Release CXX flags : -O3 -DNDEBUG -fPIC -Wall -Wno-sign-compare -Wno-uninitialized -- Debug CXX flags : -g -fPIC -Wall -Wno-sign-compare -Wno-uninitialized -- Build type : Release -- -- BUILD_SHARED_LIBS : ON -- BUILD_python : ON -- BUILD_matlab : OFF -- BUILD_docs : ON -- cpu_ONLY : ON -- USE_OPENCV : ON -- USE_LEVELDB : ON -- USE_LMDB : ON -- ALLOW_LMDB_NOLOCK : OFF -- -- Dependencies: -- BLAS : Yes (Open) -- Boost : Yes (ver. 1.58) -- glog : Yes -- gflags : Yes -- protobuf : Yes (ver. 2.6.1) -- lmdb : Yes (ver. 0.9.17) -- LevelDB : Yes (ver. 1.18) -- Snappy : Yes (ver. 1.1.3) -- OpenCV : Yes (ver. 2.4.9.1) -- CUDA : No -- -- Python: -- Interpreter : /usr/bin/python2.7 (ver. 2.7.12) -- Libraries : /usr/lib/x86_64-linux-gnu/libpython2.7.so (ver 2.7.12) -- NumPy : /usr/lib/python2.7/dist-packages/numpy/core/include (ver 1.11.0) -- -- Documentaion: -- Doxygen : No -- config_file : -- -- Install: -- Install path : /home/guyadong/caffe/caffe-master/build/install -- -- Configuring done -- Generating done -- Build files have been written to: /home/guyadong/caffe/caffe-master/build

参考资料:
《ubuntu16.04+caffe(CPU only)&hdf5.h: No such file or directory》

原文链接:https://www.f2er.com/ubuntu/356108.html

猜你在找的Ubuntu相关文章