ubuntu16.04+cuda8.0+cudnnv5+opencv3.0+python2.7安装Caffe

 版权声明:本文为博主原创文章,未经博主允许不得转载。https://mp.csdn.net/postedit/88713008

1.查看系统版本:cat /proc/version

 2.查看ubuntu版本:sudo lsb_release -a

3.克隆Caffe

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

 修改Makefile.config 

cp Makefile.config.example Makefile.config

 USE_CUDNN := 1 

 OPENCV_VERSION := 3  

 WITH_PYTHON_LAYER := 1

       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/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

 修改Makefile文件

 

NVCCFLAGS +=-ccbin=$(CXX) -Xcompiler-fPIC $(COMMON_FLAGS)

LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_hl hdf5

对应改为:

 

NVCCFLAGS += -D_FORCE_INLINES -ccbin=$(CXX) -Xcompiler -fPIC $(COMMON_FLAGS)

LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_serial_hl hdf5_serial

4.编译

make all -j8

错误1:

./include/caffe/common.hpp:5:27: fatal error: gflags/gflags.h: No such file or directory

解决方法:

sudo apt-get install libgflags-dev

错误2:

fatal error: glog/logging.h: No such file or directory

解决方法:

apt-get install libgoogle-glog-dev

错误3:

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

解决方法:

 用protoc从caffe/src/caffe/proto/caffe.proto生成caffe.pb.h和caffe.pb.cc

protoc src/caffe/proto/caffe.proto --cpp_out=.

错误4:

bash: protoc: command not found

解决方法: 

apt-get install protobuf-compiler

错误5:

./include/caffe/util/mkl_alternate.hpp:14:19: fatal error: cblas.h: No such file or directory

解决方法: 

apt-get install libblas-dev

错误6: 

src/caffe/layers/hdf5_data_layer.cpp:13:18: fatal error: hdf5.h: No such file or directory: 

解决方法:

apt-get install libhdf5-serial-dev

错误7: 

./include/caffe/util/db_lmdb.hpp:8:18: fatal error: lmdb.h: No such file or directory

解决方法:

apt-get install liblmdb-dev

然后make runtest

make pycaffe

成功后进入caffe\python

进入python,import caffe。

错误8:

ImportError: No module named caffe

尝试进入python2再import caffe

错误9:

 ImportError: No module named skimage.io

解决方法:apt-get install python-skimage

make clean

再make pycaffe,进入Python2,import caffe成功。

到此在python2的时候caffe可以成功安装,但我的默认是python3.5.所以通过以下方式

修改python的优先级:

update-alternatives --install /usr/bin/python python /usr/bin/python2 150

update-alternatives --install /usr/bin/python python /usr/bin/python3 100

再进入Python环境直接是python2

这里把python的路径写进配置文件:

mousepad ~/.bashrc

export PYTHONPATH="~/caffe/python":$PYTHONPATH

防止出现找不到caffe的错误。

重新make pycaffe,再import 成功。

到这里Caffe编译成功。

贴一份我的makefile.config以及Makefile文件:

https://download.csdn.net/download/sinat_38011533/11097333

 

https://download.csdn.net/download/sinat_38011533/11097330

/include/caffe/util/cudnn.hpp: In function 'void caffe::cudnn::setConvolutionDesc(cudnnConvolutionStruct**, cudnnTensorDescriptor_t, cudnnFilterDescriptor_t, int, int, int, int)':
./include/caffe/util/cudnn.hpp:112:3: error: too few arguments to function 'cudnnStatus_t cudnnSetConvolution2dDescriptor(cudnnConvolutionDescriptor_t, int, int, int, int, int, int, cudnnConvolutionMode_t, cudnnDataType_t)'
   CUDNN_CHECK(cudnnSetConvolution2dDescriptor(*conv,
   ^
In file included from ./include/caffe/util/cudnn.hpp:5:0,
                 from ./include/caffe/util/device_alternate.hpp:40,
                 from ./include/caffe/common.hpp:19,
                 from ./include/caffe/blob.hpp:8,
                 from ./include/caffe/data_transformer.hpp:8,
                 from src/caffe/layers/image_data_layer.cpp:10:
/usr/local/cuda/include/cudnn.h:500:27: note: declared here
 cudnnStatus_t CUDNNWINAPI cudnnSetConvolution2dDescriptor( cudnnConvolutionDescriptor_t convDesc,
                           ^
Makefile:577: recipe for target '.build_release/src/caffe/layers/image_data_layer.o' failed
make: *** [.build_release/src/caffe/layers/image_data_layer.o] Error 1
root@51c9cd09c880:/home/caffe#

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值