非root caffe linux环境配置

非root caffe linux环境配置

  • 环境依赖
    • 安装protobuf
      • 安装
      • 报错
      • 环境变量
    • 安装boost
      • 安装
      • 环境变量
    • 安装gflags,glog
      • 安装
    • 安装leveldb ,lbdb,hdf5,openblas
  • 修改caffe Makefile.config 文件
  • Caffe 安装
    • Error
  • Caffe 测试
  • 参考

环境依赖

cuda的环境服务器已经装好,另外我经常用的是anaconda中的python,所以在编译caffe之前只需要安装以下依赖库: (由于没有root权限,所有包的安装都采用源码安装的方式,有root的按官网所示安装即可。)

  1. protobuf 3.5.1
  2. snappy
  3. leveldb
  4. openCV
  5. boost 1.68.0
  6. lbdb
  7. gflags
  8. glog
  9. hdf5
  10. openblas, atlas, mkl三选一

安装protobuf

安装

cd ~/source/
git clone https://github.com/google/protobuf.git
cd protobuf/
./autogen.sh
#prefix是指定安装目录,没有root权限的可以随意设置一个,如:$HOME/bin等,
#之后记得修改 ~/.bashrc 文件
./configure --prefix=$HOME/bin 
make
make install

报错

  1. 安装google/protobuf报错:/autogen.sh: 48: autoreconf: not found
    缺少依赖包。安装这个包之前必须要安装m4, autoconf, automake, libtool这些包,具体安装方法,请参考https://blog.csdn.net/qq_30549833/article/details/72955881
    此处只记录一下这些包的网址。
wget http://mirrors.kernel.org/gnu/m4/m4-1.4.13.tar.gz 
wget http://mirrors.kernel.org/gnu/autoconf/autoconf-2.65.tar.gz
wget http://mirrors.kernel.org/gnu/automake/automake-1.11.tar.gz
wget http://mirrors.kernel.org/gnu/libtool/libtool-2.2.6b.tar.gz 
  1. configure.ac:3: error: AC_CHECK_SIZEOF: requires literal arguments
    …/…/lib/autoconf/types.m4:765: AC_CHECK_SIZEOF is expanded from
    configure.ac:3: the top level

    autoconf 版本不对,不能装2.66的。重新下个版本号>2.66的,再重新进行编译,安装即可

环境变量

非root用户,只能在bashrc 文件中,添加属于该用户的环境变量,再激活该文件,之后系统会自动加载该文件。

vim ~/.bashrc 
#添加环境变量
export PATH=$HOME/bin
export LIBRARY_PATH=$HOME/bin/lib:$LIBRARY_PATH
export LD_LIBRARY_PATH=$HOME/bin/lib:$LD_LIBRARY_PATH

安装boost

安装

cd ~/source/
wget “http://sourceforge.net/projects/boost/files/boost/1.68.0/boost_1_68_0.tar.gz”
tar xzf boost_1_68_0.tar.gz
cd boost_1_68_0
./bootstrap.sh --prefix=$HOME/bin/boost
./b2
./b2 install

环境变量

vim ~/.bashrc 
#添加环境变量
export BOOST_INCLUDEDIR=$HOME/bin/boost/include:$BOOST_INCLUDEDIR

安装gflags,glog

需要先安装gflags,再安装glog。

安装

cd ~/source/
git clone https://github.com/gflags/gflags/release/
mkdir build && cd build
#cmake 的时候要指定shared_libs=on,
#否则之后会很多关于share的error。
cmake  -DBUILD_SHARED_LIBS=ON -DGFLAGS_NAMESPACE=google -G”Unix Makefiles” ../ 
make
make prefix=/$HOME/bin install
cd ~/source/
wget https://google-glog.googlecode.com/files/glog-0.3.3.tar.gz
tar zxvf glog-0.3.3.tar.gz
cd glog-0.3.3
./configure --prefix=$HOME/bin
make && make install

安装leveldb ,lbdb,hdf5,openblas

这个是caffe的处理图片数据需要的包。具体安装方式也是大同小异。以下只给出网址。

git clone git://github.com/xianyi/OpenBLAS
git clone https://github.com/LMDB/lmdb
git clone https://github.com/google/leveldb
git https://support.hdfgroup.org/ftp/HDF5/current/src/hdf5-1.10.4.tar

修改caffe Makefile.config 文件

按照官网的教程,我们需要修改Makefile.config 中的路径,主要包括:

  1. opencv是3版本的,取消注释 OPENCV_VERSION=3
  2. 修改cuda目录
  3. 设置BLAS方式和include/lib的路径
  4. 如果是用 的anaconda的python,设置其目录和python_include 目录
  5. 修改 INCLUDE_DIRS 和LIBRARY_DIRS,将之前安装的依赖包的 include 和lib文件路径,写进去。
    其实仔细看看这个config原文件就行,里面说的挺清楚的。

Caffe 安装

终于可以开始caffe 安装了,虽然你已经安装了各路依赖包,但是这个过程中还是少不了各路妖魔鬼怪的出现。ok!Let’s go.

make
make test
make runtest
make pycaffe
make pytest

Error

  1. 报错信息
    /home/alex/usr/local/include/leveldb/status.h:26:10: error: expected ‘;’ at end of member declaration Status() noexcept : state_(nullptr) { }
    /home/alex/usr/local/include/leveldb/status.h:26:12: note: C++11 ‘noexcept’ only available with -std=c++11 or -std=gnu++11 …

这是因为 make 的时候没有指定用c++11进行编译,
搜索了好久,终于找到了解决方案:
https://stackoverflow.com/questions/10851247/how-to-activate-c-11-in-cmake

对于cmake>3.1, 打开cmake的安装目录,在CMakeLists.txt file第一行中,写入

set (CMAKE_CXX_STANDARD 11)
  1. 报错信息
    (gflags_reporting.cc.o): relocation R_X86_64_32 against.rodata.str1.1’ can not be used when making a shared object; recompile with -fPIC …

解决办法是:
https://github.com/BVLC/caffe/issues/2171,
有很多种方案,我选择的是
(1) edit CMakeCache.txt
(2) Change:  CMAKE_CXX_FLAGS:STRING=-fPIC
(3) re-compile and install
  1. 报错信息
    caffe error while loading shared libraries: libgflags.so.2.2: cannot open shared object file: No such file or directory

这就是安装gflags的时候,没有设置共享导致的error。
解决方法:从新安装,参考一下博客
https://blog.csdn.net/Amazingren/article/details/81873514
之后类似的错误也可依葫芦画瓢。
  1. 报错信息
    HDF5 header version与HDF5 library不匹配的error

原因主要是系统存在多个版本的hdf5,
我的问题主要是anaconda和刚才装的发生了冲突。
解决办法,卸载其中一个:
conda install hdf5=版本号
  1. 报错信息
    pycaffe TypeError: new() got an unexpected keyword argument ‘file’

解决方案:
https://github.com/BVLC/caffe/issues/6143
python 里面的probuf 和刚才的probuf的版本不太对,
检查probuf包的版本是否大于3.5.0,都升级到3.5.1

Caffe 测试

如果上面都没有问题,终于可以进行caffe 的测试了。

#命令行中输入
python
#测试
import caffe

完美!如果还是报错的话,想想看你刚才是不是在安装caffe 的时候,是不是没有进行 make pytest 的测试呢?

参考

感谢网上这么多的资料,终于让我成功装上了caffe。
感谢Github,CSDN以及caffe活跃的社区。
https://blog.csdn.net/happyflyy/article/details/53431772
https://groups.google.com/forum/#!forum/caffe-users
https://www.jianshu.com/p/e587e2dd1bea
https://www.ibm.com/support/knowledgecenter/zh/SSEPGG_10.5.0/com.ibm.db2.luw.qb.server.doc/doc/c0050566.html

你可能感兴趣的:(环境配置)