ubuntu14.04 编译caffe

来源:互联网 发布:高中数学视频教学软件 编辑:程序博客网 时间:2024/06/05 11:47

环境:ubuntu14.04+cuda8.0+caffe+tensorflow+anaconda3,显卡1050ti

装anaconda\cuda\caffe遇到的坑实在太多了根本记不下来,但是还是想分享一下掉坑经历,所以就从编译caffe开始记录了

下面放一下Makefile.config,主要改的是cudNN和conda的一些配置

## 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-8.0# 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 := 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_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 := /usr/anaconda3# 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.6m PYTHON_INCLUDE := $(ANACONDA_HOME)/include/python3.6m \                 $(ANACONDA_HOME)/lib/python3.6/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/includeLIBRARY_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# 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 := 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 ?= @
按照官方编译流程

cp Makefile.config.example Makefile.config# Adjust Makefile.config (for example, if using Anaconda Python, or if cuDNN is desired)make allmake testmake runtest
在最后runtest总是遇到两个错误

一个是hdf5版本不符合,说header是1.8.11库里的是1.8.17

Warning! ***HDF5 library version mismatched error***The HDF5 header files used to compile this application do not matchthe version used by the HDF5 library to which this application is linked.Data corruption or segmentation faults may occur if the application continues.This can happen when an application was compiled by one version of HDF5 butlinked with a different version of static or shared HDF5 library.You should recompile the application or check your shared library relatedsettings such as 'LD_LIBRARY_PATH'.You can, at your own risk, disable this warning by setting the environmentvariable 'HDF5_DISABLE_VERSION_CHECK' to a value of '1'.Setting it to 2 or higher will suppress the warning messages totally.Headers are 1.8.11, library is 1.8.17

尝试把conda装一下1.8.11:

conda install hdf5=1.8.11
但是很奇怪地提示package not found

另一个问题更加不知所云,类似这样的提示

*** Aborted at 1482144515 (unix time) try "date -d @1482144515" if you are using GNU date ***PC: @     0x7f3e328ff7d0 (unknown)*** SIGSEGV (@0x100000001) received by PID 2700 (TID 0x7f3e32f61880) from PID 1; stack trace: ***    @     0x7f3e313a14b0 (unknown)    @     0x7f3e328ff7d0 (unknown)    @     0x7f3e328cbc93 caffe::caffe_rng_rand()    @     0x7f3e32940a88 caffe::InternalThread::StartInternalThread()    @     0x7f3e3291ecfe caffe::DataReader::Body::Body()    @     0x7f3e3291f3ba caffe::DataReader::DataReader()    @     0x7f3e3276579b caffe::DataLayer<>::DataLayer()    @     0x7f3e327657e2 caffe::Creator_DataLayer<>()    @     0x7f3e327f8602 caffe::LayerRegistry<>::CreateLayer()    @     0x7f3e328a79c5 caffe::Net<>::Init()    @     0x7f3e328a94d1 caffe::Net<>::Net()    @     0x7f3e328b386a caffe::Solver<>::InitTrainNet()    @     0x7f3e328b4c77 caffe::Solver<>::Init()    @     0x7f3e328b501a caffe::Solver<>::Solver()    @     0x7f3e32913b23 caffe::Creator_SGDSolver<>()    @           0x40a6c9 train()    @           0x4071c0 main    @     0x7f3e3138c830 __libc_start_main    @           0x4079e9 _start    @                0x0 (unknown)Segmentation fault (core dumped)

最后发现官方教程中其实提供了非官方编译方法

mkdir buildcd buildcmake ..make allmake installmake runtest
详情可见installation-CMake Build

http://caffe.berkeleyvision.org/installation.html

顺利地哭出来,第一种方法从晚上8点一直刚到第二天4点,第二种用了不到半小时

0 0
原创粉丝点击