Ubuntu 64bit下手动安装深度学习包Caffe记录(CPU)

来源:互联网 发布:周思成网络课程百度云 编辑:程序博客网 时间:2024/06/01 22:05

前言
之前在电脑上安装Caffe都是使用的简单安装(sudo…sudo..do),这几天闲下来折腾起了手动安装。这样做主要是为了方便进行移植,这里将所有的依赖库安装到了/home/pc_name(你自己的电脑账户名,下同)/local_install/目录下。博主在Ubuntu 64bit上安装成功,现在将整个的安装过程记录下来,希望对各位看官有所帮助。若各位看官需要本次安装所需的全部安装包可以QQ联系我(2414385027)。
整篇文章基本讲干货,其他的什么介绍之类的就省略了-_-||…

1. Protobuf安装

tar zxvf protobuf-cpp-3.4.1.tar.gzcd protobuf-cpp-3.4.1/./configure --prefix=/home/pc_name/local_installmakemake install

安装完成之后为了校验安装的正确性,查看对应目录下有没有protoc文件

ls ~/local_install/bin/protoc

为了能在命令行运行,将该目录加入到PATH中去 export PATH=~/local_install/bin/:$PATH将其写入到

/home/pc_name/.bashrc

2. BOOST安装

tar zxvf boost_1_56_0.tar.gzcd boost_1_56_0/./bootstrap.sh --with-libraries=system,thread,python./b2./b2 installcp -r boost/ /home/pc_name/local_install/include/cp stage/lib/* /home/pc_name/local_install/lib/

3. CFLAGS安装

tar zxvf gflags-2.2.1.tar.gzcd gflags-2.2.1/mkdir build && cd buildcmake ..ccmake ..

若未能识别ccmake需要执行下面命令进行安装

sudo apt-get install cmake-curses-gui

CFLAGS配置
按照上面的进行配置完成之后按C键,之后G键生成Makefile文件

make   make install 

CFLAGS在Caffe中主要起到命令行参数解析的作用,这与protobuf功能类似,只是参数输入源不同。CFLAGS的使用方法可参考Caffe源码中的tools/caffe.cpp

4. GLOG安装

tar zxvf glog-0.3.5.tar.gzcd glog-0.3.5/./configure --prefix=/home/pc_name/local_install/makemake install

5. OpenBLAS安装

unzip OpenBLASv0.2.20.zipmake –jmake PREFIX=/home/pc_name/local_install/ install

6. HDF5安装

tar xvf hdf5-1.10.1.tarcd hdf5-1.10.1/./configure --prefix=/home/pc_name/local_install/make -j && make install

7. OpenCV安装

unzip opencv-3.0.0.zipcd opencv-3.0.0/mkdir build && cd buildcmake ..ccmake ..

OpenCV配置注意项

makemake install

安装完成

8. LMDB安装

tar zxvf lmdb-LMDB_0.9.21.tar.gzcd lmdb-LMDB_0.9.21/make

将生成的lmdb.h拷贝到/home/pc_name/local_install/include目录下,liblmdb.so拷贝到/home/pc_name/local_install/lib目录下。

9. LEVELDB安装

tar zxvf leveldb-1.20.tar.gzcd leveldb-1.20/makecp -r include/leveldb ~/local_install/include/cp libleveldb.so* ~/local_install/lib/

10. Snappy安装

tar zxvf snappy-1.1.1.tar.gzcd snappy-1.1.1/./configure --prefix=/home/pc_name/local_install/make && make install

在所有的附加库安装完成之后得到的2级目录结构是这样的

.├── bin├── include│   ├── boost│   ├── gflags│   ├── glog│   ├── google│   ├── leveldb│   ├── opencv│   └── opencv2├── lib│   ├── cmake│   └── pkgconfig└── share    ├── doc    ├── hdf5_examples    └── OpenCV16 directories

11. Caffe安装

至于Caffe的安装需要的是配置好Makefile.config文件就好了,下面提供本次讲解使用的文件内容(只是用CPU

## Refer to http://caffe.berkeleyvision.org/installation.html# Contributions simplifying and improving our build system are welcome!# cuDNN acceleration switch (uncomment to build with cuDNN).# USE_CUDNN := 1# CPU-only switch (uncomment to build without GPU support).CPU_ONLY := 1# uncomment to disable IO dependencies and corresponding data layers# USE_OPENCV := 0# USE_LEVELDB := 0# USE_LMDB := 0# uncomment to allow MDB_NOLOCK when reading LMDB files (only if necessary)#   You should not set this flag if you will be reading LMDBs with any#   possibility of simultaneous read and write# ALLOW_LMDB_NOLOCK := 1# Uncomment if you're using OpenCV 3OPENCV_VERSION := 3# To customize your choice of compiler, uncomment and set the following.# N.B. the default for Linux is g++ and the default for OSX is clang++# CUSTOM_CXX := g++# CUDA directory contains bin/ and lib/ directories that we need.CUDA_DIR := /usr/local/cuda# On Ubuntu 14.04, if cuda tools are installed via# "sudo apt-get install nvidia-cuda-toolkit" then use this instead:# CUDA_DIR := /usr# CUDA architecture setting: going with all of them.# For CUDA < 6.0, comment the *_50 through *_61 lines for compatibility.# For CUDA < 8.0, comment the *_60 and *_61 lines for compatibility.CUDA_ARCH := -gencode arch=compute_20,code=sm_20 \        -gencode arch=compute_20,code=sm_21 \        -gencode arch=compute_30,code=sm_30 \        -gencode arch=compute_35,code=sm_35 \        -gencode arch=compute_50,code=sm_50 \        -gencode arch=compute_52,code=sm_52 \        -gencode arch=compute_60,code=sm_60 \        -gencode arch=compute_61,code=sm_61 \        -gencode arch=compute_61,code=compute_61# BLAS choice:# atlas for ATLAS (default)# mkl for MKL# open for OpenBlasBLAS := open# Custom (MKL/ATLAS/OpenBLAS) include and lib directories.# Leave commented to accept the defaults for your choice of BLAS# (which should work)!# BLAS_INCLUDE := `/path/to/your/blas# BLAS_LIB := /path/to/your/blas# Homebrew puts openblas in a directory that is not on the standard search path# BLAS_INCLUDE := $(shell brew --prefix openblas)/include# BLAS_LIB := $(shell brew --prefix openblas)/lib# This is required only if you will compile the matlab interface# MATLAB directory should contain the mex binary in /bin.# MATLAB_DIR := /usr/local# MATLAB_DIR := /Applications/MATLAB_R2012b.app# NOTE: this is required only if you will compile the python interface.# We need to be able to find Python.h and numpy/arrayobject.h.PYTHON_INCLUDE := /usr/include/python2.7 \        /usr/lib/python2.7/dist-packages/numpy/core/include# Anaconda Python distribution is quite popular. Include path:# Verify anaconda location, sometimes it's in root.# ANACONDA_HOME := $(HOME)/anaconda# PYTHON_INCLUDE := $(ANACONDA_HOME)/include \        # $(ANACONDA_HOME)/include/python2.7 \        # $(ANACONDA_HOME)/lib/python2.7/site-packages/numpy/core/include# Uncomment to use Python 3 (default is Python 2)# PYTHON_LIBRARIES := boost_python3 python3.5m# PYTHON_INCLUDE := /usr/include/python3.5m \#                 /usr/lib/python3.5/dist-packages/numpy/core/include# We need to be able to find libpythonX.X.so or .dylib.PYTHON_LIB := /usr/lib# PYTHON_LIB := $(ANACONDA_HOME)/lib# Homebrew installs numpy in a non standard path (keg only)# PYTHON_INCLUDE += $(dir $(shell python -c 'import numpy.core; print(numpy.core.__file__)'))/include# PYTHON_LIB += $(shell brew --prefix numpy)/lib# Uncomment to support layers written in Python (will link against Python libs)# WITH_PYTHON_LAYER := 1# Whatever else you find you need goes here.INCLUDE_DIRS := /home/sucker/local_install/include $(PYTHON_INCLUDE)\ /usr/local/includeLIBRARY_DIRS := /home/sucker/local_install/lib $(PYTHON_LIB)\ /usr/local/lib /usr/lib# If Homebrew is installed at a non standard location (for example your home directory) and you use it for general dependencies# INCLUDE_DIRS += $(shell brew --prefix)/include# LIBRARY_DIRS += $(shell brew --prefix)/lib# NCCL acceleration switch (uncomment to build with NCCL)# https://github.com/NVIDIA/nccl (last tested version: v1.2.3-1+cuda8.0)# USE_NCCL := 1# Uncomment to use `pkg-config` to specify OpenCV library paths.# (Usually not necessary -- OpenCV libraries are normally installed in one of the above $LIBRARY_DIRS.)# USE_PKG_CONFIG := 1# N.B. both build and distribute dirs are cleared on make cleanBUILD_DIR := buildDISTRIBUTE_DIR := distribute# Uncomment for debugging. Does not work on OSX due to https://github.com/BVLC/caffe/issues/171# DEBUG := 1# The ID of the GPU that 'make runtest' will use to run unit tests.TEST_GPUID := 0# enable pretty build (comment to see full commands)Q ?= @

编辑好config文件之后就是进行编译了,就是make命令。之后为了检验安装是否成功需要进行如下验证

make testmake runtest

本人在其中遇到这个错误

.build_release/tools/caffe: error while loading shared libraries: libboost_system.so.1.56.0: cannot open shared object file: No such file or directory make: *** [runtest] Error 127

解决办法
在/home/pc_name/下编辑.bashrc文件,添加

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/pc_name/local_install/lib

这里写图片描述