SSD学习系列(一)ubuntu18.0.4上编译caffe SSD源代码

代码下载

git clone https://github.com/weiliu89/caffe.git xxx/caffe_ssd
cd caffe
git checkout ssd   //切换到ssd branch

需要注意的地方是  代码下载后其根目录变成了caffe_ssd。

代码编译


cd xxx/caffe_ssd

cp Makefile.config.example Makefile.config

sudo make clean

sudo make -j8

sudo make pycaffe -j8

当然在编译前,要编辑Makefile.config如下

 

注意,cudnn源代码不需要更新,因为ssd代码已经升级到可以支持cudnn6了。

编译过程遇到的问题

1)找不到NVCC

NVCC src/caffe/layers/reduction_layer.cumake: /usr/local/cuda/bin/nvcc: Command not foundMakefile:588: recipe for target 
'.build_release/cuda/src/caffe/layers/reduction_layer.o' failedmake: *** 
[.build_release/cuda/src/caffe/layers/reduction_layer.o] Error 127

解决办法就是在Makefile.config里面更新CUDA_DIR值如下:

CUDA_DIR := /usr

2)找不到stdlib.h和math.h

CXX src/caffe/layers/concat_layer.cppIn file included from 
/usr/include/c++/6/bits/stl_algo.h:59:0,                 from 
/usr/include/c++/6/algorithm:62,                 from 
src/caffe/layers/sigmoid_cross_entropy_loss_layer.cpp:1:/usr/include/c++/6/cstdlib:75:25: 
fatal error: stdlib.h: No such file or directory

解决办法是,将cstdlib和cmath里面的 #include_next <stdlib.h>和 #include_next <math.h>修改成:

#include <stdlib.h>和 #include <math.h>

其实这个问题,应该可以通过将gcc和g++版本降级成4.8来解决,但是本平台cudnn版本为7.1,是用gcc/g++6来编译的,所以如果降低了gcc版本会引起新的问题。

3)找不到libopenblas.so

/usr/bin/x86_64-linux-gnu-ld: cannot find -lopenblas
collect2: error: ld returned 1 exit status

解决办法是,更新Makefile.config来选则atlas而不是openblas。

# BLAS choice:</font>
# atlas for ATLAS (default)</font>
# mkl for MKL</font>

BLAS := atlas
#BLAS := open

4)找不到cv::Mat::updateContinuityFlag()的定义

build_release/examples/cpp_classification/classification.o: 
In function `Classifier::WrapInputLayer(std::vector<cv::Mat, std::allocator<cv::Mat> >*)':classification.cpp:(.text+0x1d85): undefined reference to 
`cv::Mat::updateContinuityFlag()'.build_release/examples/cpp_classification/classification.
o: In function `Classifier::SetMean(std::__cxx11::basic_string<char, 
std::char_traits<char>, std::allocator<char> > const&)':classification.cpp:(.text+0x2dfc): 
undefined reference to `cv::Mat::updateContinuityFlag()'

一般地象这种错误的解法就是将classification.cpp改成classification.cpp1,即不让它参与编译。但是examples/ssd_detect.cpp也调用了updateContinuityFlag(),所以另外一种解决办法就是让程序来连接libopencv_world.so,而不是零散的opencv模块库。

# 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

5)protobuf

如果遇到下面protobuf apis没有定义(如下所示),而使用命令sudo apt-get install libprotobuf-dev却告知已经安装最新版本protobuf时。则很有可能软链接libprotobuf.so指向的是/usr/lib或/usr/lib/x86_64-linux-gnu下面的旧库。使它以及libprotoc.so指向新版本就能解决问题。

.build_release/lib/libcaffe.so: undefined reference to `google::protobuf::Message::InitializationErrorString[abi:cxx11]() const'
.build_release/lib/libcaffe.so: undefined reference to `google::protobuf::Message::SpaceUsed() const'
.build_release/lib/libcaffe.so: undefined reference to `google::protobuf::internal::WireFormatLite::WriteBytesMaybeAliased(int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, google::protobuf::io::CodedOutputStream*)

 

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 9
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ltshan139

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值