ubuntu16安装caffe

个人建议安装好anaconda后先安装caffe,再安装tensorflow-gpu

在github上下载caffe:

sudo apt-get install git#安装git

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

到下载的caffe目录下

将Makefile.config.example的内容复制到Makefile.config并打开该文件(make命令只能make *.config文件)
sudo cp Makefile.config.example Makefile.config#复制文件

sudo gedit 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 := 1
# USE_LEVELDB := 0
# USE_LMDB := 0
# This code is taken from https://github.com/sh1r0/caffe-android-lib
# USE_HDF5 := 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 through *_61 lines for compatibility.
# For CUDA < 8.0, comment the *_60 and *_61 lines for compatibility.
# For CUDA >= 9.0, comment the *_20 and *_21 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_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 OpenBlas
BLAS := atlas
# 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
 MATLAB_DIR := /usr/local/MATLAB/R2017b
# 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)/anaconda3
 PYTHON_INCLUDE := $(ANACONDA_HOME)/include \
		 $(ANACONDA_HOME)/include/python3.6m \
		 $(ANACONDA_HOME)/lib/python3.6/site-packages/numpy/core/include

# Uncomment to use Python 3 (default is Python 2)
 PYTHON_LIBRARIES := boost_python3 python3.6m
 PYTHON_INCLUDE := /usr/include/python3.6m \
                 /usr/lib/python3.6/dist-packages/numpy/core/include \
                  /home/liu/anaconda3/include/python3.6m

# We need to be able to find libpythonX.X.so or .dylib.
#PYTHON_LIB := /usr/lib
 PYTHON_LIB := $(ANACONDA_HOME)/lib \
               $(ANACONDA_HOME)/pkgs/python-3.6.5-hc3d631a_2/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
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include /usr/lib/x86_64-linux-gnu/hdf5/serial/include
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /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

# 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 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 ?= @

 

 

踩的坑:

error1.

In file included from /usr/include/c++/5/atomic:38:0,
                 from /usr/local/include/google/protobuf/io/coded_stream.h:113,
                 from .build_release/src/caffe/proto/caffe.pb.h:23,
                 from ./include/caffe/util/cudnn.hpp:8,
                 from ./include/caffe/util/device_alternate.hpp:40,
                 from ./include/caffe/common.hpp:19,
                 from ./include/caffe/util/math_functions.hpp:9,
                 from src/caffe/solvers/nesterov_solver.cu:1:
/usr/include/c++/5/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
 #error This file requires compiler and library support \
  ^
In file included from /usr/include/c++/5/atomic:38:0,
                 from /usr/local/include/google/protobuf/io/coded_stream.h:113,
                 from .build_release/src/caffe/proto/caffe.pb.h:23,
                 from ./include/caffe/util/cudnn.hpp:8,
                 from ./include/caffe/util/device_alternate.hpp:40,
                 from ./include/caffe/common.hpp:19,
                 from ./include/caffe/util/math_functions.hpp:9,
                 from src/caffe/solvers/adam_solver.cu:1:
/usr/include/c++/5/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
 #error This file requires compiler and library support \
  ^
In file included from /usr/include/c++/5/atomic:38:0,
                 from /usr/local/include/google/protobuf/io/coded_stream.h:113,
                 from .build_release/src/caffe/proto/caffe.pb.h:23,
                 from ./include/caffe/util/cudnn.hpp:8,
                 from ./include/caffe/util/device_alternate.hpp:40,
                 from ./include/caffe/common.hpp:19,
                 from src/caffe/util/im2col.cu:3:
/usr/include/c++/5/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
 #error This file requires compiler and library support \
  ^
In file included from /usr/include/c++/5/atomic:38:0,
                 from /usr/local/include/google/protobuf/io/coded_stream.h:113,
                 from .build_release/src/caffe/proto/caffe.pb.h:23,
                 from ./include/caffe/util/cudnn.hpp:8,
                 from ./include/caffe/util/device_alternate.hpp:40,
                 from ./include/caffe/common.hpp:19,
                 from ./include/caffe/util/math_functions.hpp:9,
                 from src/caffe/solvers/adadelta_solver.cu:1:
/usr/include/c++/5/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
 #error This file requires compiler and library support \
  ^
In file included from /usr/include/c++/5/atomic:38:0,
                 from /usr/local/include/google/protobuf/io/coded_stream.h:113,
                 from .build_release/src/caffe/proto/caffe.pb.h:23,
                 from ./include/caffe/util/cudnn.hpp:8,
                 from ./include/caffe/util/device_alternate.hpp:40,
                 from ./include/caffe/common.hpp:19,
                 from ./include/caffe/util/math_functions.hpp:9,
                 from src/caffe/solvers/rmsprop_solver.cu:1:
/usr/include/c++/5/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
 #error This file requires compiler and library support \
  ^
In file included from /usr/include/c++/5/atomic:38:0,
                 from /usr/local/include/google/protobuf/io/coded_stream.h:113,
                 from .build_release/src/caffe/proto/caffe.pb.h:23,
                 from ./include/caffe/util/cudnn.hpp:8,
                 from ./include/caffe/util/device_alternate.hpp:40,
                 from ./include/caffe/common.hpp:19,
                 from ./include/caffe/util/math_functions.hpp:9,
                 from src/caffe/solvers/sgd_solver.cu:1:
/usr/include/c++/5/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
 #error This file requires compiler and library support \
  ^
Makefile:610: recipe for target '.build_release/cuda/src/caffe/solvers/nesterov_solver.o' failed
make: *** [.build_release/cuda/src/caffe/solvers/nesterov_solver.o] Error 1
make: *** 正在等待未完成的任务....
Makefile:610: recipe for target '.build_release/cuda/src/caffe/solvers/adam_solver.o' failed
make: *** [.build_release/cuda/src/caffe/solvers/adam_solver.o] Error 1
Makefile:610: recipe for target '.build_release/cuda/src/caffe/solvers/adadelta_solver.o' failed
make: *** [.build_release/cuda/src/caffe/solvers/adadelta_solver.o] Error 1
Makefile:610: recipe for target '.build_release/cuda/src/caffe/solvers/sgd_solver.o' failed
make: *** [.build_release/cuda/src/caffe/solvers/sgd_solver.o] Error 1
Makefile:610: recipe for target '.build_release/cuda/src/caffe/solvers/rmsprop_solver.o' failed
make: *** [.build_release/cuda/src/caffe/solvers/rmsprop_solver.o] Error 1
Makefile:610: recipe for target '.build_release/cuda/src/caffe/util/im2col.o' failed
make: *** [.build_release/cuda/src/caffe/util/im2col.o] Error 1
In file included from /usr/include/c++/5/atomic:38:0,
                 from /usr/local/include/google/protobuf/io/coded_stream.h:113,
                 from .build_release/src/caffe/proto/caffe.pb.h:23,
                 from ./include/caffe/util/cudnn.hpp:8,
                 from ./include/caffe/util/device_alternate.hpp:40,
                 from ./include/caffe/common.hpp:19,
                 from ./include/caffe/util/math_functions.hpp:9,
                 from src/caffe/solvers/adagrad_solver.cu:1:
/usr/include/c++/5/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
 #error This file requires compiler and library support \
  ^
Makefile:610: recipe for target '.build_release/cuda/src/caffe/solvers/adagrad_solver.o' failed
make: *** [.build_release/cuda/src/caffe/solvers/adagrad_solver.o] Error 1
In file included from /usr/include/c++/5/atomic:38:0,
                 from /usr/local/include/google/protobuf/io/coded_stream.h:113,
                 from .build_release/src/caffe/proto/caffe.pb.h:23,
                 from ./include/caffe/util/cudnn.hpp:8,
                 from ./include/caffe/util/device_alternate.hpp:40,
                 from ./include/caffe/common.hpp:19,
                 from src/caffe/util/math_functions.cu:8:
/usr/include/c++/5/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
 #error This file requires compiler and library support \
  ^
Makefile:610: recipe for target '.build_release/cuda/src/caffe/util/math_functions.o' failed
make: *** [.build_release/cuda/src/caffe/util/math_functions.o] Error 1

解决方案:1.在CMakelists.txt中加入下面的代码

#将下面的内容添加到CMakeLists.txt当中
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
if(COMPILER_SUPPORTS_CXX11)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
elseif(COMPILER_SUPPORTS_CXX0X)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
else()
        message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
endif()


#或将CMakeLists.txt中下面的代码段
if(UNIX OR APPLE)
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -Wall")
endif()if()
改为
if(UNIX OR APPLE)
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -Wall -std=c++11")
endif()if()

#还有可能需要改makefile文件:在对应的行后加上-std=c++11
CXXFLAGS += -pthread -fPIC $(COMMON_FLAGS) $(WARNINGS) -std=c++11
NVCCFLAGS += -D_FORCE_INLINES -ccbin=$(CXX) -Xcompiler -fPIC $(COMMON_FLAGS) -std=c++11
LINKFLAGS += -pthread -fPIC $(COMMON_FLAGS) $(WARNINGS) -std=c++11

                 2.可能是因为有两个.so和.a libs(我也不知道啥意思)

                    这种情况输入下面的代码后重新编译即可

make clean
export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
export LIBRARY_PATH=/usr/local/lib:$LIBRARY_PATH
sudo ldconfig

最后

2. ./include/caffe/util/cudnn.hpp:8:34: fatal error: caffe/proto/caffe.pb.h: 没有那个文件或目录

sudo pip install protobuf --upgrade -i http://pypi.douban.com/simple 
sudo pip install pillow --upgrade -i http://pypi.douban.com/simple

c++11支持解决方案

你可能感兴趣的:(软件安装,caffe,ubuntu16)