准备工作

Faster-RCNN源码下载地址:

Matlab版本:https://github.com/ShaoqingRen/faster_rcnn

Python版本:https://github.com/rbgirshick/py-faster-rcnn
基于tf版本:https://github.com/endernewton/tf-faster-rcnn

本文用到的是Python版本,在Linux下运行。

Matlab版本的训练过程:
http://blog.csdn.net/sinat_30071459/article/details/50546891

配置 caffe

网上的教程很多,请参考:
http://blog.csdn.net/yhaolpz/article/details/71375762

编译安装faster-rcnn

官方的参考链接:https://github.com/rbgirshick/py-faster-rcnn

1.安装cython,python-opencv,easydict
2.下载py-faster-rcnn

# Make sure to clone with --recursive
git clone --recursive https://github.com/rbgirshick/py-faster-rcnn.git

3.进入py-faster-rcnn/lib, 执行make

遇到的bug

python setup.py build_ext --inplace
Traceback (most recent call last):
  File "setup.py", line 58, in <module>
    CUDA = locate_cuda()
  File "setup.py", line 53, in locate_cuda
    for k, v in cudaconfig.iteritems():
AttributeError: 'dict' object has no attribute 'iteritems'
make: *** [all] Error 1

对于这个错误,我的服务器用python2就好了,即修改Makefile文件为:

python2 setup.py build_ext --inplace

4.进入py-faster-rcnn\caffe-fast-rcnn

  • 执行 cp Makefile.config.example Makefile.config
  • 然后,配置Makefile.config文件,与配置caffe时,修改该文件类似,这里我的修改是:
a.若使用cudnn,则将 
#USE_CUDNN := 1 
修改成: 
USE_CUDNN := 1

b.若使用的opencv版本是3的,则 将 
#OPENCV_VERSION := 3 
修改为: 
OPENCV_VERSION := 3
否则
OPENCV_VERSION := 2

其他的地方根据服务器情况,自行修改
  • 配置好Makefile.config文件后,执行:make -j8 && make pycaffe

5.下载pre-computed Faster R-CNN detectors

cd $FRCN_ROOT
./data/scripts/fetch_faster_rcnn_models.sh

各种bug

问题1
F0423 21:09:48.410542 71131 layer_factory.hpp:81] Check failed: registry.count(type) == 1 (0 vs. 1) Unknown layer type: Python (known types: AbsVal, Accuracy, ArgMax, BNLL, BatchNorm, BatchReindex, Bias, Concat, ContrastiveLoss, Convolution, Data, Deconvolution, Dropout, DummyData, ELU, Eltwise, Embed, EuclideanLoss, Exp, Filter, Flatten, HDF5Data, HDF5Output, HingeLoss, Im2col, ImageData, InfogainLoss, InnerProduct, LRN, Log, MVN, MemoryData, MultinomialLogisticLoss, PReLU, Pooling, Power, ROIPooling, ReLU, Reduction, Reshape, SPP, Scale, Sigmoid, SigmoidCrossEntropyLoss, Silence, Slice, SmoothL1Loss, Softmax, SoftmaxWithLoss, Split, TanH, Threshold, Tile, WindowData)
*** Check failure stack trace: ***
Aborted (core dumped)

解决方法:


#将Makefile.confige 中的
#WITH_PYTHON_LAYER := 1 
修改为 
WITH_PYTHON_LAYER := 1
问题2
Traceback (most recent call last):
  File "./tools/demo.py", line 149, in <module>
    demo(net, im_name)
  File "./tools/demo.py", line 98, in demo
    vis_detections(im, cls, dets, thresh=CONF_THRESH)
  File "./tools/demo.py", line 47, in vis_detections
    fig, ax = plt.subplots(figsize=(12, 12))
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/pyplot.py", line 1185, in subplots
    fig = figure(**fig_kw)
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/pyplot.py", line 535, in figure
    **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_qt4agg.py", line 46, in new_figure_manager
    return new_figure_manager_given_figure(num, thisFig)
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_qt4agg.py", line 53, in new_figure_manager_given_figure
    canvas = FigureCanvasQTAgg(figure)
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_qt4agg.py", line 76, in __init__
    FigureCanvasQT.__init__(self, figure)
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_qt4.py", line 68, in __init__
    _create_qApp()
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_qt5.py", line 138, in _create_qApp
    raise RuntimeError('Invalid DISPLAY variable')
RuntimeError: Invalid DISPLAY variable

解决办法:

 在demo.py中import matplotlib.pyplot as plt后加入
 plt.switch_backend('agg') 
问题3
In file included from ./include/caffe/util/cudnn.hpp:5:0,
                 from ./include/caffe/util/device_alternate.hpp:40,
                 from ./include/caffe/common.hpp:19,
                 from src/caffe/common.cpp:7:
/usr/local/cuda8/include/cudnn.h:952:27: note: declared here
 cudnnStatus_t CUDNNWINAPI cudnnSetPooling2dDescriptor(
                           ^
make: *** [.build_release/src/caffe/common.o] Error 1

faster rcnn与cudnn v5不兼容解决方法
1) 用最新caffe源码的以下文件替换掉faster rcnn 的对应文件

include/caffe/layers/cudnn_relu_layer.hpp, src/caffe/layers/cudnn_relu_layer.cpp, src/caffe/layers/cudnn_relu_layer.cu

include/caffe/layers/cudnn_sigmoid_layer.hpp, src/caffe/layers/cudnn_sigmoid_layer.cpp, src/caffe/layers/cudnn_sigmoid_layer.cu

include/caffe/layers/cudnn_tanh_layer.hpp, src/caffe/layers/cudnn_tanh_layer.cpp, src/caffe/layers/cudnn_tanh_layer.cu

2)用caffe源码中的这个文件替换掉faster rcnn 对应文件

include/caffe/util/cudnn.hpp

3)将 faster rcnn 中的 src/caffe/layers/cudnn_conv_layer.cu 文件中的所有

cudnnConvolutionBackwardData_v3 函数名替换为 cudnnConvolutionBackwardData
cudnnConvolutionBackwardFilter_v3函数名替换为 cudnnConvolutionBackwardFilter

2 errors detected in the compilation of "/tmp/tmpxft_00006a2c_00000000-13_cudnn_conv_layer.compute_50.cpp1.ii".
make: *** [.build_release/cuda/src/caffe/layers/cudnn_conv_layer.o] Error 1
make: *** Waiting for unfinished jobs....
collect2: error: ld returned 1 exit status
make: *** [.build_release/tools/upgrade_net_proto_binary.bin] Error 1
collect2: error: ld returned 1 exit status
make: *** [.build_release/tools/extract_features.bin] Error 1
collect2: error: ld returned 1 exit status
make: *** [.build_release/tools/compute_image_mean.bin] Error 1
问题4
CUDA driver version is insufficient for CUDA runtime version

解决办法:
这可能是由于cuda版本不对,现改成cuda8,并安装相应的cudnn
进入/py-faster-rcnn/lib$ 修改setup.py文件

修改setup.py文件中第43行,将cuda为cuda8

default_path = pjoin(os.sep, 'usr', 'local', 'cuda', 'bin')

修改后

default_path = pjoin(os.sep, 'usr', 'local', 'cuda8', 'bin')

修改setup.py文件中第135行,将sm_35为sm_37

'nvcc': ['-arch=sm_35',

修改后

'nvcc': ['-arch=sm_37',

然后清楚原来的编译,重新窒息make进行编译
这时可能会遇到下面的问题:

nvcc fatal   : Value 'sm_37' is not defined for option 'gpu-architecture'

解决方法:
在编译之前,加入:

export PATH=/usr/local/cuda-8.0/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda8/lib64:$LD_LIBRARY_PATH

通过echo$PATHecho$LD_LIBRARY_PATH来查看是否成功加入

Logo

瓜分20万奖金 获得内推名额 丰厚实物奖励 易参与易上手

更多推荐