在centos6.X上安装caffe

0.编译安装gcc4.8.5

由于centos6.x中的gcc版本老旧,不支持c++11所以要安装gcc4.8.5,以下是安装教程。参考CentOS 6.4 编译安装 gcc-4.8.0

解压安装包进入目录执行download_prerequisites脚本./contrib/download_prerequisites

新建buildmkdir build

进入build目录执行

../configure -enable-checking=release -enable-languages=c,c++ -disable-multilib(生成Makefile文件)

修改Makefile文件中prefix=安装路径,这里的安装路径是/home/guanjun/caffe_lib/third/gcc-4.8.5

注意本文以下的安装路径都是/home/guanjun/caffe_lib/third下的对应目录

make -j32
make install

安装完成后要将gcc4.8.5中bin目录添加到环境变量(临时创建env_caffe.sh)

在env_caffe.sh中添加

export PATH=/home/guanjun/caffe_lib/third/gcc-4.8.5/bin:$PATH

1.安装Anaconda python 环境

执行安装文件

./Anaconda2-4.2.0-Linux-x86_64.sh

注意在提示的最后的选项选no即不添加到.bashrc

之后同样在env_caffe.sh中添加export PATH=/home/guanjun/anaconda2/bin:$PATH

之后执行下面的命令

source ~/env_caffe.sh

因为编译boost时会用到python环境

2.编译安装boost

解压安装包然后执行

./bootstrap.sh
./b2 install --prefix=安装路径

参考boost Installation

3.编译安装opencv

解压安装包然后进入安装包执行

mkdir build
cd build
ccmake ../

按照提示加载配置文件(按c)、修改cmake_install_prefix路径为安装路径、

WITH CUDA WITH CUFFT WITH JASPER分别设置为off,按照提示保存退出(按c 按g),然后执行

make -j32
make install

4.编译安装glog

解压然后依次执行

./configure --prefix=安装路径
make -j32
make intstall

5.编译安装gflags

解压然后进入解压文件依次执行

mkdir build
cd build
export CXXFLAGS="-fPIC"
ccmake ../

按c加载配置文件、设置安装路径按c g退出,之后执行

make -j32
make install

6.编译安装lmdb

首先下载lmdb安装包执行git clone https://github.com/LMDB/lmdb

打开lmdb中MakeFile文件、修改安装路径

make -j
make install

7.安装openblas

下载新版OpenBLASgit clone https://github.com/xianyi/OpenBLAS

进入OpenBLAS打开目录中cpuid.h文件在倒数第二行添加#define NO_AVX2 1024然后执行

make -j32
make install PREFIX=安装路径

8.编译安装hdf5

解压、进入文件执行

./configure --prefix=安装路径
make -j32
make install

9.编译安装protobuf

解压、进入文件执行

./configure --prefix=安装路径
make -j32
make install

之后将protobuf添加到环境变量中(env_caffe.sh)export PATH=/home/guanjun/caffe_lib/third/protobuf/bin:$PATH

在编译caffe前确保env_caffe.sh文件如下

export PATH=/home/guanjun/caffe_lib/third/gcc-4.8.5/bin:/home/guanjun/anaconda2/bin:/home/guanjun/caffe_lib/third/protobuf/bin:$PATH
export PYTHONPATH=/home/guanjun/caffe/py-R-FCN/caffe/python:$PYTHONPATH
export LD_LIBRARY_PATH=/home/guanjun/caffe_lib/third_source/leveldb/out-shared:/home/guanjun/anaconda2/lib:/usr/local/cuda/lib64:/home/guanjun/caffe_lib/third/boost/lib:/home/guanjun/caffe_lib/third/hdf5/lib:/home/guanjun/caffe_lib/third/lmdb/lib:/home/guanjun/caffe_lib/third/openblas_v1/lib:/home/guanjun/caffe_lib/third/opencv/lib:/home/guanjun/caffe_lib/third/protobuf/lib:/home/guanjun/caffe_lib/third/glog/lib:/home/guanjun/caffe_lib/third/gflags/lib:/home/guanjun/caffe_lib/third/glibc-2.14/lib:/home/guanjun/caffe_lib/third/gcc-4.8.5/lib64:$LD_LIBRARY_PATH

/home/guanjun/替换成/home/你的用户名/

同时,保证caffe中的Makefile.config和下面的配置文件一样

# 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
D_PATH := /home/guanjun/caffe_lib/third
# 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
CUDA_ARCH := -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 := /home/guanjun/caffe_lib/third/openblas_v1/include
BLAS_LIB := /home/guanjun/caffe_lib/third/openblas_v1/lib # 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/guanjun/anaconda2
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 := $(D_PATH)/protobuf/include
#INCLUDE_DIRS := /data/shiyang/anaconda2/include
INCLUDE_DIRS += $(D_PATH)/hdf5/include
INCLUDE_DIRS += $(D_PATH)/gflags/include
INCLUDE_DIRS += $(D_PATH)/glog/include
INCLUDE_DIRS += $(D_PATH)/opencv/include
INCLUDE_DIRS += $(D_PATH)/boost/include
INCLUDE_DIRS += $(D_PATH)/lmdb/include
INCLUDE_DIRS += $(D_PATH)/glibc-2.14/include
INCLUDE_DIRS += $(D_PATH)/gcc-4.8.5/include
INCLUDE_DIRS += /home/guanjun/caffe_lib/third_source/leveldb/include LIBRARY_DIRS := $(D_PATH)/protobuf/lib
#LIBRARY_DIRS := /data/shiyang/anaconda2/lib
LIBRARY_DIRS += $(D_PATH)/hdf5/lib
LIBRARY_DIRS += $(D_PATH)/gflags/lib
LIBRARY_DIRS += $(D_PATH)/glog/lib
LIBRARY_DIRS += $(D_PATH)/opencv/lib
LIBRARY_DIRS += $(D_PATH)/boost/lib
LIBRARY_DIRS += $(D_PATH)/lmdb/lib
LIBRARY_DIRS += $(D_PATH)/glibc-2.14/lib
LIBRARY_DIRS += $(D_PATH)/gcc-4.8.5/lib64
LIBRARY_DIRS += /home/guanjun/caffe_lib/third_source/leveldb/out-shared 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 # N.B. both build and distribute dirs are cleared on `make clean`
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 ?= @

之后执行source ~/env_caffe.sh

进入caffe目录执行

make -j32
make runtest
make pycaffe

将caffe的python添加到环境变量export PYTHONPATH=/home/guanjun/caffe/py-R-FCN/caffe/python:$PYTHONPATH就是env_caffe.sh中的第二行。

新建一个python文件测试import caffe是否可用。


在本地Ubuntu16.04上安装caffe

1.安装cuda

先把错配的显卡驱动清理干净

sudo apt-get --purge remove nvidia-*

https://developer.nvidia.com/cuda-downloads下载对应的deb文件(cuda-repo-ubuntu1604-8-0-local-ga2_8.0.61-1_amd64.deb)

到deb的下载目录下

sudo dpkg -i cuda-repo-ubuntu1604-8-0-local-ga2_8.0.61-1_amd64.deb
sudo apt-get update
sudo apt-get install cuda
sudo reboot

参考ubuntu 14.04 现在安装cuda7.5超级简便,惊了

2.安装caffe

安装依赖

sudo apt-get install -y opencl-headers build-essential protobuf-compiler \
libprotoc-dev libboost-all-dev libleveldb-dev hdf5-tools libhdf5-serial-dev \
libopencv-core-dev libopencv-highgui-dev libsnappy-dev \
libatlas-base-dev cmake libstdc++6-4.8-dbg libgoogle-glog0v5 libgoogle-glog-dev \
libgflags-dev liblmdb-dev git python-pip gfortran libopencv-dev
sudo apt-get clean

下载caffe并安装caffe python依赖

git clone https://github.com/BVLC/caffe.git
cd caffe
cd python
for req in $(cat requirements.txt); do sudo pip install $req; done

准备Makefile.config,以便它可以ubuntu上构建

cd ../
cp Makefile.config.example Makefile.config

修改Makefile.config如下

## 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 := 1
# 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_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 := 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/guan/anaconda2
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 := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial/
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu /usr/lib/x86_64-linux-gnu/hdf5/serial/ # 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 # N.B. both build and distribute dirs are cleared on `make clean`
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 ?= @

注意修改路径。

执行

make all -j
make runtest
make pycaffe

执行echo "export PYTHONPATH=/opt/cat-dogs/repo/caffe/python:$PYTHONPATH" >> ~/.bashrc这句也可以不添加到.bashrc,可以自己写个env_caffe.sh每次用caffe的时候source env_caffe.sh


编译caffe时出现的问题和解决方法(本地ubuntu16.04和服务器centos)

1.编译caffe时出现的错误

错误

.build_release/src/caffe/proto/caffe.pb.h:12:2: error: #error This file was generated by a newer version of protoc which is

解决方法下载新版本的、编译安装

sudo apt-get install autoconf automake libtool
git clone https://github.com/google/protobuf
./autogen.sh
./configure
make
make check
sudo make install

错误

/usr/include/boost/python/detail/wrap_python.hpp:50:23: fatal error: pyconfig.h: No such file or directory

解决方法

export CPLUS_INCLUDE_PATH=/usr/include/python2.7
make clean
make all -j2

错误

fatal error: caffe/proto/caffe.pb.h: No such file or directory

解决方法

protoc src/caffe/proto/caffe.proto --cpp_out=.
mkdir include/caffe/proto
mv src/caffe/proto/caffe.pb.h include/caffe/proto

2.make runtest出现的错误

错误

.build_release/tools/caffe: error while loading shared libraries: libprotobuf.so.14: cannot open shared object file: No such file or directory
Makefile:526: recipe for target 'runtest' failed

解决方法添加链接路径

export LD_LIBRARY_PATH=/usr/local/lib/

3.import caffe时出现的错误

错误

No module named google.protobuf.internal

解决方法

/home/guan/anaconda2/bin/pip install protobuf

错误

/home/guan/anaconda2/bin/../lib/libstdc++.so.6: version `GLIBCXX_3.4.21' not found

解决方法

conda install libgcc

错误

No module named google.protobuf.internal

解决方法

/home/guan/anaconda2/bin/pip install protobuf

4.runtest出现的错误

错误

src/caffe/test/test_gradient_based_solver.cpp:373: Failure
The difference between expected_updated_weight and solver_updated_weight is 1.7136335372924805e-07, which exceeds error_margin, where
expected_updated_weight evaluates to 9.6857547760009766e-06,
solver_updated_weight evaluates to 9.8571181297302246e-06, and
error_margin evaluates to 1.0000000116860974e-07.
[ FAILED ] NesterovSolverTest/2.TestNesterovLeastSquaresUpdateWithEverything, where TypeParam = caffe::GPUDevice<float> (6484 ms)

解决方法

执行export CUDA_VISIBLE_DEVICES=0,重新执行测试。

参考runtest出现的问题

ubuntu16.04和服务器 caffe 安装的更多相关文章

  1. 阿里云ECS服务器环境搭建——ubuntu16.04图形界面的安装

    阿里云ECS服务器环境搭建——ubuntu16.04图形界面的安装 最近琢磨着想在服务器上搭建一个hexo博客,于是就在阿里云上买了一个云服务器ECS,远程接入后默认给的是一个命令窗口,没有图形界面, ...

  2. 路由器安装ubuntu-16.04.1-server-amd64出现“无法安装busybox-initramfs”错误。向目标系统中安装busybox-initramfs软件包时出现一个错误。请检查/var/log/syslog或查看第四虚拟控制台以获得详细

    公司的路由器要ubuntu服务器进行路由网络功能的管理,在安装的时候出现下面的错误提示: 安装ubuntu-16.04.1-server-amd64出现“无法安装busybox-initramfs”错 ...

  3. Ubuntu16.04 LTS下apt安装WireShark

    Ubuntu16.04 LTS下apt安装WireShark 安装与配置 首先通过apt安装WireShark: $ sudo apt install wireshark 会同时安装许多的依赖包,其中 ...

  4. ubuntu16.04下sublime text3安装和配置

    ubuntu16.04下sublime text3安装和配置 2018年04月20日 10:31:08 zhengqijun_ 阅读数:1482 1.安装方法 1)使用ppa安装 sudo add-a ...

  5. Ubuntu16.04上用源代码安装ICE

    ubuntu16.04上用源代码安装ICE

  6. Ubuntu16.04下,erlang安装和rabbitmq安装步骤

    文章来源: Ubuntu16.04下,erlang安装和rabbitmq安装步骤 准备工作,先下载erlang和rabbitmq的安装包,注意他们的版本,版本不对可能会导致rabbitmq无法启动,这 ...

  7. caffe搭建--caffe在invidia+cpu 酷睿2Q9300 + ubuntu16.04.2上面的安装和编译过程

    本文原创,转载请注明出处. ------------------------------------------------分割线-------------------------------- 概要 ...

  8. ubuntu16.04+cuda8.0+caffe

    =========== 如果出现nvidia-smi failed to communicate with nvidia driver,循环登录情况,则: sudo apt-get remove -- ...

  9. caffe2+cuda+Ubuntu16.04(u盘安装)

    安装caffe2 预先准备.安装gflags及autoconf及GLOG https://github.com/caffe2/caffe2/issues/1810 一.下载源代码通过网盘 https: ...

随机推荐

  1. hdu4035 Maze (树上dp求期望)

    dp求期望的题. 题意: 有n个房间,由n-1条隧道连通起来,实际上就形成了一棵树, 从结点1出发,开始走,在每个结点i都有3种可能: 1.被杀死,回到结点1处(概率为ki) 2.找到出口,走出迷宫 ...

  2. dedecms--自定义session存值取值

    最近在用用dedecms开发项目,开发项目中遇到需要通过session存储信息在其他页面调取使用,但是对dedecms里面自带的session存储使用不好,我需要存储的是用户登录的时候信息,于是我就使 ...

  3. Redis数据结构之整数集合

    整数集合是Redis用于保存整数值的集合抽象数据结构,它可以保存类型为int16_t .int32_t或者int64_t的整数值,并且保证集合中不会出现重复元素. 一.整数集合数据结构定义 参数说明: ...

  4. JFinal2.0极速开发视频教程发布【转】

    原文:http://blog.dreamlu.net/blog/79 目前JFinal越来越火爆,而且使用的公司越来越多.鉴于市面上JFinal的学习资源不多,我们开始基于JFinal2.0录制学习视 ...

  5. LinkedList类的基本方法的用法

    package cn.zmh.LinkedList; import java.util.Iterator; import java.util.LinkedList; public class Link ...

  6. Redhat7/centOs7 安装配置python3.6.5

    centos默认安装python2,设置py2和py3并存的方法如下: sudo yum install openssl-devel -y sudo yum install zlib-devel -y ...

  7. Angularjs: call other scope which in iframe

    Angularjs: call other scope which in iframe -------------------------------------------------------- ...

  8. python requests接收chunked编码问题-python源码修改

    python requests接收chunked编码问题-python源码修改 学习了:https://blog.csdn.net/wangzuxi/article/details/40377467

  9. jQuery开发之Ajax

    1.load()方法 (1)load()方法是jQuery中最经常使用和最简单的Ajax方法,能载入远程HTML代码,并插入代码中. 它的结构为: load(url [,data] [,callbac ...

  10. Python常用的模块

    模块,模块就是封装了特殊功能的代码. 模块分为三种: 自定义模块 第三方模块 内置模块 自定义模块 1.自定义模块 2.模块的导入 python有大量的模块可以使用,再使用之前我们只需要导入模块就可以 ...