[普通]Centos7下的caffe编译安装简易手册

作者(passion) 阅读(1221次) 评论(0) 分类( 软件)

caffe是深度学习在图像领域广泛使用的框架,其model zoo有大量的预训练好的模型提供使用。大部分图像相关的应用部分将用到caffe。

墙裂建议大家使用linux系统,原因如下。

  • linux系统(大部分公司为CentOS或者Ubuntu),才是实际开发中用到的系统,提前熟悉一下命令行,对于实际应用和开发都很有必要。

  • 相对于Windows而言,linux下的依赖包安装非常简单。

  • Windows下编译经常会出现大量问题,且现在网上Windows下caffe出现问题的解决方案非常少

  • 大量的二次开发和扩展都只有linux版本

1.说明

下面是安装caffe的一些笔记,写的不明白的,欢迎大家提问^_^

2.关于系统

这个说明是关于linux系统的,最好是centOS 7.0以上,或者ubuntu 14.04 以上 
因为低版本的装不上兼容合适的boost,opencv等库

3.配置yum源

不配的话很多依赖库都需要自己手动编译和指定caffe编译路径,耗时且经常编译不成功 
在国内的话用sohu或者163的源 
rpm -Uvh http://mirrors.sohu.com/fedora-epel/7/x86_64/e/epel-release-7-2.noarch.rpm

让新的源生效 
yum repolist

4.安装依赖的库

要确认一下,所有的库都装上了,否则编译出来可能不能使用。 
其中protobuf是用来定义layers的,leveldb是训练时存储图片数据的数据库,opencv是图像处理库,boost是通用C++库,等等...

sudo yum install protobuf-devel leveldb-devel snappy-devel opencv-devel boost-devel hdf5-devel

5.安装科学计算和python所需的部分库

sudo yum install openblas-devel.x86_64 gcc-c++.x86_64 numpy.x86_64 scipy.x86_64 python-matplotlib.x86_64 lapack-devel.x86_64 python-pillow.x86_64 libjpeg-turbo-devel.x86_64 freetype-devel.x86_64 libpng-devel.x86_64 openblas-devel.x86_64

6.安装别的依赖

sudo yum install gflags-devel glog-devel lmdb-devel

7.安装git,拉取源码

yum install git

git clone https://github.com/BVLC/caffe.git

8.安装python的pip和easy_install,方便安装软件包

wget --no-check-certificate https://bootstrap.pypa.io/ez_setup.py 
python ez_setup.py --insecure

wget https://bootstrap.pypa.io/get-pip.py

python get-pip.py

9.安装python依赖(路径根据自己的目录可能要调一下)

cd caffe/python

执行

for req in $(cat requirements.txt); do pip install $req; done

这步安装也有点慢,别急,等会儿,先去干点别的 ^_^

10.编辑caffe所需的Makefile文件

cd caffe 
cp Makefile.config.example Makefile.config 
vim Makefile.config 
Makefile.config里面有依赖库的路径,及各种编译配置,如果是没有GPU的情况下,可以参照我下面帮你改的配置文件内容:

## 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 3
# OPENCV_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 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_50,code=compute_50
# BLAS choice:
# atlas for ATLAS (default)
# mkl for MKL
# open for OpenBlas
#BLAS := atlas
BLAS := 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
BLAS_INCLUDE := /usr/include/openblas
# 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 \
# 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 := $(PYTHON_INCLUDE) /usr/local/include
LIBRARY_DIRS := $(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
# 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
BUILD_DIR := build
DISTRIBUTE_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 ?= @

11.编译caffe

make -j4 
编译可能会有点慢,你可以先去干点别的事情

  • 测试一下编译结果 
    make test 
    make runtest

12.编译pycaffe

make pycaffe -j4


« 上一篇:wifi共享上网(至尊版wifi)
« 下一篇:​MTCNN实现流程
在这里写下您精彩的评论
  • 微信

  • QQ

  • 支付宝

返回首页
返回首页 img
返回顶部~
返回顶部 img