[Caffe]ubuntu16.04下编译caffe以及py-faster-rcnn的注意事项(仅cpu,anaconda2,opencv3)

caffe的编译我是参考的caffe官方介绍。
而py-faster-rcnn在cpu下的demo运行我是参考的https://blog.csdn.net/qq_27664915/article/details/56673764
Faster_RCNN_CPU版本需要实现roi_pooling_layer.cpp和smooth_L1_loss_layer.cpp,请参考https://github.com/neuleaf/faster-rcnn-cpu
Faster_RCNN_CPU模式下进行VOC数据集训练我是参考的https://blog.csdn.net/wjx2012yt/article/details/52197698
Faster_RCNN_CPU模式下进行自己的数据集训练和前面一个链接类似,需要改些配置文件,可以看这篇文章:https://blog.csdn.net/wjx2012yt/article/details/52197698
除此之外,我在ubuntu和windows下尝试训练时均出现了loss=nan的现象,参考https://blog.csdn.net/kuaitoukid/article/details/42120961这篇博客,将base_lr调小。

一些注意点:
①Makefile.config文件中的INCLUDE_DIRS改成
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial/

WITH_PYTHON_LAYER := 1 这里也要记得去掉注释才能在caffe中使用python

最后加个
LINKFLAGS := -Wl,-rpath,$(HOME)/anaconda2/lib

②Makefile文件中的LIBRARIES
LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_serial_hl hdf5_serial opencv_core opencv_highgui
opencv_imgproc opencv_imgcodecs

如果出现了

很长,前面的报错省略掉
xx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)@GLIBCXX_3.4.21' /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libgflags.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::compare(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const@GLIBCXX_3.4.21'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libglog.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_create(unsigned long&, unsigned long)@GLIBCXX_3.4.21' .build_release/lib/libcaffe.so: undefined reference to `std::out_of_range::out_of_range(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
collect2: error: ld returned 1 exit status
Makefile:627: recipe for target '.build_release/tools/extract_features.bin' failed(或者是别的文件)
make: *** [.build_release/tools/extract_features.bin] Error 1

这样的情况,使用conda install libgcc

④若python下import caffe报出ImportError: No module named google.protobuf.internal 的话,使用命令行pip install protobuf
sudo apt-get install python-protobuf

⑤最后,在~/.bashrc处要配置下环境变量,在最后加上个export PYTHONPATH=~/caffe/python:$PYTHONPATH 然后source ~/.bashrc 即可

最后的最后,感谢http://www.voidcn.com/article/p-vyhrkbir-yc.html这篇博客对我caffe编译过程中发生问题的帮助。

importError: cpu_nms.so: undefined symbol: PyFPE_jbuf.问题
这个问题是我在尝试cpu_caffe下的py-faster-rcnn初步应用的最后一步-运行demo.py出现的问题,出现该种问题的关键是因为运行环境下存在不同的python环境(我的Ubuntu下自带的python2.7.12,而我自己也装了python2.7.13),两种python的版本和路径可以通过运行/usr/bin/python2.7python 命令了解到。我是不想卸载掉我的anaconda的,因为我之前很多依赖是使用anaconda安装的,因此我首先想的是:把anaconda的python调整至2.7.12,使用命令行conda install python=2.7.12 ,然后打开terminal输入python,可以清晰地看到anaconda下的python已经改为2.7.12版本了,接下来再次运行demo.py,晕,还是显示之前的importError: cpu_nms.so: undefined symbol: PyFPE_jbuf. 问题,最后使出了最后一招:/usr/bin/python2.7 demo.py --cpu --net zf ,直接使用系统自带的python2.7,成功。
最后,为了更方便地使用python命令,我认为可以通过ln命令,把/usr/bin/python2.7软链接到anaconda的pytho下。

猜你喜欢

转载自blog.csdn.net/mjl960108/article/details/81081918