编译 Faster Rcnn

来源:互联网 发布:mac cosmetics美国官网 编辑:程序博客网 时间:2024/05/22 16:23

编译 Faster Rcnn

Rcnn 是比较经典的做目标检测的算法,今天准备学习一下,啥都不用说,先把程序调通。

  • 一、编译caffe
    编译caffe是最麻烦的事情。。
首先下载rcnn 的代码git clone --recursive https://github.com/rbgirshick/py-faster-rcnn.git 
然后开始编译cd /home/mmt/Desktop/py-faster-rcnn/libmake 
编译caffecd /home/mmt/Desktop/py-faster-rcnn/caffe-fast-rcnncp Makefile.config.example Makefile.config 然后修改里面的内容WITH_PYTHON_LAYER := 1  USE_CUDNN := 1将这两句前面的 # 号去掉然后make -j8 && make pycaffe 
出现错误1src/caffe/net.cpp:8:18: fatal error: hdf5.h: No such file or directory解决方法:将Makefile.config中的INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/includeLIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib修改为:INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serialLIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnumake将 Makefile中LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_hl hdf5修改为:LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_serial_hl hdf5_serial重新编译:make -j8 && make pycaffe 出现错误2 error: too few arguments to functioncudnnStatus_t cudnnSetPooling2dDescriptor(cudnnPoolingDescriptor_t, cudnnPoolingMod解决方法:将BVLC(https://github.com/BVLC/caffe)中的下列文件copy 到相应的文件夹,即将这三个文件夹里的cudnn开头的文件全部换成新的:./include/caffe/util/cudnn.hpp./include/caffe/layers/cudnn_conv_layer.hpp./include/caffe/layers/cudnn_relu_layer.hpp./include/caffe/layers/cudnn_sigmoid_layer.hpp./include/caffe/layers/cudnn_tanh_layer.hpp./src/caffe/layers/cudnn_conv_layer.cpp./src/caffe/layers/cudnn_conv_layer.cu./src/caffe/layers/cudnn_relu_layer.cpp./src/caffe/layers/cudnn_relu_layer.cu./src/caffe/layers/cudnn_sigmoid_layer.cpp./src/caffe/layers/cudnn_sigmoid_layer.cu./src/caffe/layers/cudnn_tanh_layer.cpp./src/caffe/layers/cudnn_tanh_layer.cumake cleanmake -j8出现build_release/lib/libcaffe.so:对‘cv::imdecode(cv::_InputArray const&, int)’未定义的引用对于各种cv出错:解决方法:修改Makefile:LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_serial_hl hdf5_serial matio opencv_core opencv_highgui opencv_imgproc opencv_imgcodecs下次编译之前要 make cleanmake clean make -j8编译成功make pycaffepython/caffe/_caffe.cpp:11:31: fatal error: numpy/arrayobject.h: No such file or directory解决方法:然后对照 Makefile.config将第二行加一个localPYTHON_INCLUDE := /usr/include/python2.7 \/usr/local/lib/python2.7/dist-packages/numpy/core/include重新编译成功
  • 二、下载models
    ./data/scripts/fetch_faster_rcnn_models.sh

这里写图片描述
然后 跑一个demo
./tools/demo.py

这里写图片描述这里写图片描述
这里写图片描述
编译到此就成功了。

  • 三、训练 Fast RCNN 出错
    1、在网络初始化到loss_bbox层时会出现smoothL1loss.cpperror :bottom.size=4(3vs.4) If weightsare used, must specify both inside and outside weights之类错误!
解决方法:参考 http://blog.csdn.net/qq_34220460/article/details/72778714找到SmoothL1loss.cpp,找到出错误的那部分看到has_weights=(bottom.size()>=3);把它改成has_weights=(bottom.size()==3);然后下面的if语句用//注释掉。接着还要改,看到下面的这几行代码:    CHECK_EQ(bottom[0]->channels(),bottom[3]->channels());   CHECK_EQ(bottom[0]->height(), bottom[3]->height());   CHECK_EQ(bottom[0]->width(), bottom[3]->width());这三行,也要用//注释掉。Ok!!!!!再重新编译!!!!make clean     make  -j8

2、AttributeError: ‘module’ object has no attribute ‘text_format’
解决方法:参考网址 http://blog.csdn.net/qq_33202928/article/details/72526710

解决办法1:sudo pip install protobuf==2.5.0解决办法2:在文件./lib/fast_rcnn/train.py增加一行import google.protobuf.text_format 即可解决问题

3、TypeError: ‘numpy.float64’ object cannot be interpreted as an index
参考网址:http://m.blog.csdn.net/hongbin_xu/article/details/77278329

原创粉丝点击