注意:要求Ubuntu系统预先安装opencv和cuda8.0

下载caffe,一般可从GitHub获得,解压缩。

一、编译

1、cd  /home/(服务器的名字)/caffe(caffe目录下)
2、cp Makefile.config.example Makefile.config

打开并修改Makefile.config

若使用GPU加速,则 use CUDNN:=1 去除注释;

若使用OpenCV3版本,则OPENCV_VERSION := 3 去除注释;

根据显卡计算能力删除(一般只报警告)

Ubuntu下caffe 配置(总结踩过的坑)

Python包含目录要正确:

Ubuntu下caffe 配置(总结踩过的坑)

3、cd /home/**(您服务器的名字)/caffe

4、mkdir build

5、cd build

6、cmake ..(cmake和..中间有一个空格)

7、make all -j16("‐j16"是使用 CPU 的多核进行编译,可以极大地加速编译的速度)

8、make install

9、make runtest(这一步不是必须的)

10、make pycaffe(编译pycaffe)

 二、编译过程中可能出现的错误

错误1:/usr/include/boost/python/detail/wrap_python.hpp:50:23: fatal error: pyconfig.h:没有那个文件或目录compilation terminated.

            Makefile:575: recipe for target '.build_release/src/caffe/layer_factory.o' failed 

            make:***[./build_release/src/caffe/layer_factory.o] Error 1

解决1:终端输入

            $make clean

            $export CPLUS_INCLUDE_PATH=/usr/include/python2.7

            $make  -j16

错误2:src/caffe/layers/hdf5_output_layer.cpp:3:18: fatal error: hdf5.h: 没有那个文件或目录compilation terminated.

           Makefile:575: recipe for target '.build_release/src/caffe/layers/hdf5_output_layer.o' failed

           make: *** [.build_release/src/caffe/layers/hdf5_output_layer.o] Error 1

           make: *** 正在等待未完成的任务....

解决2:Makefile.config文件第85行左右,添加/usr/include/hdf5/serial/到INCLUDE_DIRS,如下第一行改为第二行:

            Makefile.config文件第173行左右,把hdf5_hl和hdf5修改为hdf5_serial_hl和hdf5_serial,如下第三行改为第四行:

             1.INCLUDE_DIRS :=$(PYTHON_INCLUDE)/usr/local/incllude

             2.INCLUDE_DIRS :=$(PYTHON_INCLUDE)/usr/local/incllude  /usr/include/hdf5/serial/

             3.LIBRARIES+= glog flags protobuf boost_system boost_filesystem m hdf5_hl hdf5

             4.LIBRARIES+= glog flags protobuf boost_system boost_filesystem m hdf5_serial_hl hdf5_serial

错误3:/usr/bin/ld:cannot find -lhdf5_hl

             /usr/bin/ld:cannot find -lhdf5

             collect2:error:ld returned 1 exit status

             Makefile:572: recipe for target '.build_release/lib/libcaffe.so.1.0.0' failed

             make: *** [.build_release/lib/libcaffe.so.1.0.0] Error 1

解决3:在Makefile.config中添加:

            INCLUDE_DIRS :=$(PYTHON_INCLUDE)/usr/local/incllude  /usr/include/hdf5/serial/

            LIBRARY := $(PYTHON_LIB)/usr/local/lib  /usr/lib/x86_64-linux-gnu /usr/lib/x86_64-linux-gnu/hdf5/serial

 

错误4:在代码中进行import caffe后报错ImportError:No module named _caffe

解决4:终端输入

            $make clean

            $make -j16

            $make pycaffe(关键)

错误5:caffe/util/cudnn.hpp:8:34: fatal error: caffe/proto/caffe.pb.h:没有那个文件或目录(找不到caffe.pb.h)

解决5:caffe编译过程没有问题的话,就是因为缺失文件,而缺失的文件在caffe安装根目录下的include文件夹中

            终端输入:

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

            $mkdir include/caffe/proto

            $mv src/caffe/proto/caffe.pb.h include/caffe/proto

 

错误6:训练或者测试时,遇到./build/tools/caffe:not found错误

解决6:终端执行命令需在caffe的目录下。

错误7:cudnn版本问题(提示错误是与cudnn相关)

解决7:先终端输入make clean,把caffe里面的所有与cudnn相关的.h和cpp替换成第一次配置caffe时候所用的cudnn版本(caffe/src/caffe/util下的cudnn.cpp和 

            caffe/include/caffe/layers下与cudnn相关的cpp和cu文件)

分类:

技术点:

相关文章: