代码下载
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*)