Faster R-CNN: Towards Real-Time Object Detection with Region Proposal Networks程序(Python)配置问题总结

17 篇文章 0 订阅
12 篇文章 0 订阅

目录

预先浏览

  • Faster R-CNN原文
  • 源码(python)
  • 推荐阅读CSDN Blog
  • 说明
    • 文中仅描述了我所遇到的问题,所以可能会不全。
    • 文中粘贴Error track,除了说明错误的原因外,更是为了便于检索和搜索。
    • 希望对大家有帮助,若有错误,还望指出。

Q&A

Q1: error: utils/bbox.c: No such file or directory

  • 错误描述:

    x86_64-linux-gnu-gcc: error: utils/bbox.c: No such file or directory
    x86_64-linux-gnu-gcc: fatal error: no input files
    compilation terminated.
    error: command ‘x86_64-linux-gnu-gcc’ failed with exit status 4
    make: * [all] Error 1

  • 解决方案: 手动用python生成bbox.c

    cd $FRCN_ROOT/lib/utils
    cython bbox.pyx

Q2: error: nms/cpu_nms.c: No such file or directory**

  • 错误描述:

    x86_64-linux-gnu-gcc: error: nms/cpu_nms.c: No such file or directory
    x86_64-linux-gnu-gcc: fatal error: no input files
    compilation terminated.
    error: command ‘x86_64-linux-gnu-gcc’ failed with exit status 4
    make: * [all] Error 1

  • 解决方案: 手动用python生成cpu_nms.c

    cd $FRCN_ROOT/lib/nms
    cython cpu_nms.pyx

Q3: error: nms/gpu_nms.c: No such file or directory**

  • 错误描述:

    x86_64-linux-gnu-gcc: error: nms/gpu_nms.c: No such file or directory
    x86_64-linux-gnu-gcc: fatal error: no input files
    compilation terminated.
    error: command ‘x86_64-linux-gnu-gcc’ failed with exit status 4
    make: * [all] Error 1

  • 解决方案: 手动用cython生成gpu_nms.c

    cd $FRCN_ROOT/lib/nms
    cython gpu_nms.pyx

Q4: Makefile.config not found**

  • 错误描述:

    Makefile:6: * Makefile.config not found. See Makefile.config.example.. Stop.

  • 解决方案: $FRCN_ROOT/caffe-fast-rcnn目录下,作者提供了Makefile.config.example

    cd $FRCN_ROOT/caffe-fast-rcnn
    cp Makefile.config.example Makefile.config

Q5: undefined symbol: _nms**

  • 错误描述: 当在$FRCN_ROOT/lib下make时出现

    Traceback (most recent call last):
    File “./demo.py”, line 18, in module
    from fast_rcnn.test import im_detect
    File “/home/lijiajun/py-faster-rcnn-blog/tools/../lib/fast_rcnn/test.py”, line 17, in module
    from fast_rcnn.nms_wrapper import nms
    File “/home/lijiajun/py-faster-rcnn-blog/tools/../lib/fast_rcnn/nms_wrapper.py”, line 9, in module
    from nms.gpu_nms import gpu_nms
    ImportError: /home/lijiajun/py-faster-rcnn-blog/tools/../lib/nms/gpu_nms.so: undefined symbol: _nms

  • **解决方案: **gpu_nms.so编译时有误,分3步

    • 编辑setup.py

      cd $FRCN_ROOT/lib
      vim setup.py
    • 将gpu_nms.pyx改为gpu_nms.cpp

      
      #before
      
      Extension('nms.gpu_nms',
          ['nms/nms_kernel.cu', 'nms/gpu_nms.pyx'],
          ...
      
      #after
      
      Extension('nms.gpu_nms',
          ['nms/nms_kernel.cu', 'nms/gpu_nms.cpp'],
          ...
    • 修改gpu_nms.c文件后缀为.cpp

      cd $FRCN_ROOT/lib/nms
      mv gpu_nms.c gpu_nms.cpp
      rm gpu_nms.so

Q6: Check failed: registry.count(type) == 1 (0 vs. 1) Unknown layer type**

  • 错误描述:

    I1221 19:43:06.790405 12895 layer_factory.hpp:76] Creating layer proposal
    F1221 19:43:06.790431 12895 layer_factory.hpp:80] Check failed: registry.count(type) == 1 (0 vs. 1) Unknown layer type: Python (known types: AbsVal, Accuracy, ArgMax, BNLL, Concat, ContrastiveLoss, Convolution, Data, Deconvolution, Dropout, DummyData, 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, Sigmoid, SigmoidCrossEntropyLoss, Silence, Slice, SmoothL1Loss, Softmax, SoftmaxWithLoss, Split, TanH, Threshold, Tile, WindowData)
    *** Check failure stack trace: ***
    Aborted (core dumped)

  • 解决方案: 将caffe的Makefile.config配置正确

    • Caffe must be built with support for Python layers!

      
      # In your Makefile.config, make sure to have this line uncommented
      
      WITH_PYTHON_LAYER := 1
    • 修改完成后重新编译

      cd $FRCN_ROOT/caffe-fast-rcnn
      make clean
      make -j
      make pycaffe

Q7: ImportError: No module named _caffe**

  • 错误描述:

    Traceback (most recent call last):
    File “./demo.py”, line 18, in < module>
    from fast_rcnn.test import im_detect
    File “/home/lijiajun/py-faster-rcnn-blog/tools/../lib/fast_rcnn/test.py”, line 16, in < module>
    import caffe
    File “/home/lijiajun/py-faster-rcnn-blog/tools/../caffe-fast-rcnn/python/caffe/init.py”, line 1, in < module>
    from .pycaffe import Net, SGDSolver
    File “/home/lijiajun/py-faster-rcnn-blog/tools/../caffe-fast-rcnn/python/caffe/pycaffe.py”, line 13, in < module>
    from ._caffe import Net, SGDSolver
    ImportError: No module named _caffe

  • 解决方案: 编译pycaffe

    cd $FRCN_ROOT/caffe-fast-rcnn
    make pycaffe

Q8: tkinter.TclError: no display name and no $DISPLAY environment variable**

  • 错误描述:

    Traceback (most recent call last):
    File “./demo.py”, line 149, in < module>
    demo(net, im_name)
    File “./demo.py”, line 98, in demo
    vis_detections(im, cls, dets, thresh=CONF_THRESH)
    File “./demo.py”, line 47, in vis_detections
    fig, ax = plt.subplots(figsize=(12, 12))
    File “/usr/lib/pymodules/python2.7/matplotlib/pyplot.py”, line 1046, in subplots
    fig = figure(**fig_kw)
    File “/usr/lib/pymodules/python2.7/matplotlib/pyplot.py”, line 423, in figure**kwargs)
    File “/usr/lib/pymodules/python2.7/matplotlib/backends/backend_tkagg.py”, line 79, in new_figure_manager
    return new_figure_manager_given_figure(num, figure)
    File “/usr/lib/pymodules/python2.7/matplotlib/backends/backend_tkagg.py”, line 87, in new_figure_manager_given_figure
    window = Tk.Tk()
    File “/usr/lib/python2.7/lib-tk/Tkinter.py”, line 1767, in __init__
    self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
    _tkinter.TclError: no display name and no $DISPLAY environment variable

  • 解决方案: 注释需要图形界面的代码

    • 切换到图形界面后在执行脚本。

    • 或者,修改demo.py,将调用函数vis_detections()的代码注释。

Q9: invalid conversion from ‘const int*’ to ‘int*’**

  • 错误描述:

    nms/gpu_nms.cpp: In function ‘PyObject* __pyx_pf_3nms_7gpu_nms_gpu_nms(PyObject*, PyArrayObject*, PyObject*, __pyx_t_5numpy_int32_t)’:
    nms/gpu_nms.cpp:1593:469: error: invalid conversion from ‘const int*’ to ‘int*’ [-fpermissive]
    _nms((&(__Pyx_BufPtrStrided1d(const int , __pyx_pybuffernd_keep.rcbuffer->pybuffer.buf, __pyx_t_10, __pyx_pybuffernd_keep.diminfo[0].strides))), (&__pyx_v_num_out), (&(__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float32_t , __pyx_pybuffernd_sorted_dets.rcbuffer->pybuffer.buf, __pyx_t_12, __pyx_pybuffernd_sorted_dets.diminfo[0].strides, __pyx_t_13, __pyx_pybuffernd_sorted_dets.diminfo[1].strides))), __pyx_v_boxes_num, __pyx_v_boxes_dim, __pyx_t_14, __pyx_v_device_id);
    ^
    In file included from nms/gpu_nms.cpp:253:0:
    nms/gpu_nms.hpp:1:6: error: initializing argument 1 of ‘void _nms(int*, int*, const float*, int, int, float, int)’ [-fpermissive]
    void _nms(int* keep_out, int* num_out, const float* boxes_host, int boxes_num,int boxes_dim, float nms_overlap_thresh, int device_id);
    ^
    error: command ‘arm-linux-gnueabihf-gcc’ failed with exit status 1
    make: * [all] Error 1

  • 问题分析:
    原因就是C语言编译器允许隐含性的将一个通用指针转换为任意类型的指针,包括const *而C++不允许将const 转换为非const*,所以出错。

  • 解决方案:
    将出错的函数变量__pyx_t_5numpy_int32_t*,改成int*(见红色字体)。接着,为了保证gpu_nms.cpp不再由gpu_nms.pyx自动生成,需要将setup.py中ext_modules数组下的nms/gpu_nms.pyx改为nms/gpu_nms.cpp。

    • error:

      _nms((&(__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int32_t *, __pyx_pybuffernd_keep.rcbuffer->pybuffer.buf, __pyx_t_10, __pyx_pybuffernd_keep.diminfo[0].strides))), (&__pyx_v_num_out), (&(*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float32_t , __pyx_pybuffernd_sorted_dets.rcbuffer->pybuffer.buf, __pyx_t_12, __pyx_pybuffernd_sorted_dets.diminfo[0].strides, __pyx_t_13, __pyx_pybuffernd_sorted_dets.diminfo[1].strides))), __pyx_v_boxes_num, __pyx_v_boxes_dim, __pyx_t_14, __pyx_v_device_id);

    • correct:

      _nms((&(__Pyx_BufPtrStrided1d(int*, __pyx_pybuffernd_keep.rcbuffer->pybuffer.buf, __pyx_t_10, __pyx_pybuffernd_keep.diminfo[0].strides))), (&__pyx_v_num_out), (&(*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float32_t , __pyx_pybuffernd_sorted_dets.rcbuffer->pybuffer.buf, __pyx_t_12, __pyx_pybuffernd_sorted_dets.diminfo[0].strides, __pyx_t_13, __pyx_pybuffernd_sorted_dets.diminfo[1].strides))), __pyx_v_boxes_num, __pyx_v_boxes_dim, __pyx_t_14, __pyx_v_device_id);

Q10:Check failed: error == cudaSuccess (8 vs. 0) invalid device function**

  • 错误分析:

    GPU too old or Cuda too old. Faster R-CNN的Issue讨论得还比较清楚。
    Whenever the CUDA runtime API returns “Invalid Device Function”, it means you are using code which wasn’t built for the architecture you are trying to run it on (and doesn’t have a JIT path).

  • 解决方案请参考:

Q11:Check failed: error == cudaSuccess (8 vs. 0) invalid device function**

  • 错误描述:

    Error using textread (line 165)
    File not found.
    Error in VOCevaldet (line 30)
    [ids,confidence,b1,b2,b3,b4]=textread(sprintf(VOCopts.detrespath,id,cls),’%s %f %f %f %f %f’);
    Error in voc_eval>voc_eval_cls (line 36)
    [recall, prec, ap] = VOCevaldet(VOCopts, comp_id, cls, true);
    Error in voc_eval (line 8)
    res(i) = voc_eval_cls(cls, VOCopts, comp_id, output_dir, rm_res);
    165 error(message(‘MATLAB:textread:FileNotFound’));

  • 解决方案:

    • In VOCCode, inside the VOCdevkit folder, there will be a file called VOCinit.m
    • In that, on around line 31, change the VOC.testset to ‘test’ instead of ‘val’.

2016年2月26日更新
2016年11月22日更新

Q12:Check failed: error == cudaSuccess (8 vs. 0) invalid device function**

  • 错误描述:

    python setup.py build_ext –inplace
    Traceback (most recent call last):
    File “setup.py”, line 57, in
    CUDA = locate_cuda()
    File “setup.py”, line 54, in locate_cuda
    raise EnvironmentError(‘The CUDA %s path could not be located in %s’ % (k, v))
    EnvironmentError: The CUDA lib64 path could not be located in /usr/local/cuda/lib64
    make: * [all] Error 1

  • 解决方案:

    • 1 修改lib/setup.py中cudaconfig元组中lib64的值, ‘lib64’->’lib’。因为设备不支持64位运算,所以cuda缺少lib64文件。
    • 2 显存不够大,适当增大存储(sunyiyou9提供)。

reference:
1. Github issues1
2. Github issues2


最终效果图

最终效果

### 回答1: Faster R-CNN是一种基于区域建议网络(Region Proposal Networks,RPN)的物体检测算法,旨在实现实时物体检测。它通过预测每个区域是否含有物体来生成候选框,并使用卷积神经网络CNN)来确定候选框中的物体类别。Faster R-CNN在提高检测精度的同时,也显著提高了检测速度。 ### 回答2: 在计算机视觉领域中,目标检测一直是热门研究的方向之一。近年来,基于深度学习的目标检测方法已经取得了显著的进展,并且在许多实际应用中得到了广泛的应用。其中,Faster R-CNN 是一种基于区域建议网络(Region Proposal Networks,RPN)的目标检测方法,在检测准确率和速度之间取得了很好的平衡,能够实现实时目标检测。 Faster R-CNN 的基本框架由两个模块组成:区域建议网络(RPN)和检测模块。RPN 主要负责生成候选目标框,而检测模块则利用这些候选框完成目标检测任务。具体来说,RPN 首先在原始图像上以多个尺度的滑动窗口为基础,使用卷积网络获取特征图。然后,在特征图上应用一个小型网络来预测每个位置是否存在目标,以及每个位置的目标边界框的坐标偏移量。最终,RPN 根据预测得分和位置偏移量来选择一部分具有潜在对象的区域,然后将这些区域作为候选框送入检测模块。 检测模块的主要任务是使用候选框来检测图像中的目标类别和位置。具体来说,该模块首先通过将每个候选框映射回原始图像并使用 RoI Pooling 算法来获取固定大小的特征向量。然后,使用全连接神经网络对这些特征向量进行分类和回归,以获得每个框的目标类别和精确位置。 相比于传统的目标检测方法,Faster R-CNN 具有以下优点:首先,通过使用 RPN 可以自动生成候选框,避免了手动设计和选择的过程;其次,通过共享卷积网络可以大大减少计算量,提高效率;最后,Faster R-CNN 在准确率和速度之间取得了很好的平衡,可以实现实时目标检测。 总之,Faster R-CNN 是一种高效、准确的目标检测方法,是深度学习在计算机视觉领域中的重要应用之一。在未来,随着计算机视觉技术的进一步发展,Faster R-CNN 这类基于深度学习的目标检测方法将会得到更广泛的应用。 ### 回答3: Faster R-CNN是一种结合了深度学习和传统目标检测算法的新型目标检测方法,旨在提高目标检测速度和准确率。Faster R-CNN采用了Region Proposal Network(RPN)来生成候选区域,并通过R-CNN网络对候选区域进行分类和定位。 RPN是一种全卷积神经网络,用于在图像中生成潜在的候选区域。RPN通常在卷积特征图上滑动,对每个位置预测k个候选区域和其对应的置信度得分。这样,对于输入图像,在不同大小和宽高比的Anchor上预测候选框,可以在计算上更有效率。 R-CNN网络利用卷积特征图作为输入,对RPN生成的候选区域进行分类和精确定位。与以前的目标检测方法相比,Faster R-CNN使用了共享卷积特征,使得整个检测网络可以端到端地进行训练和优化,缩短了训练时间,同时也更便于理解和改进。 Faster R-CNN不仅具有较高的准确性,还具有较快的检测速度。在各种基准测试中,Faster R-CNN与其他目标检测算法相比,都取得了优异的性能表现。总之,Faster R-CNN将目标检测引入了一个新的阶段,为实时目标检测提供了一个良好的基础。
评论 77
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值