Faster R-CNN只用CPU跑demo测试

1.下载代码和数据

git clone --recursive https://github.com/rbgirshick/py-faster-rcnn.git

2.下载demo模型数据

[root@localhost py-faster-rcnn]# ./data/scripts/fetch_faster_rcnn_models.sh
Downloading Faster R-CNN demo models (695M)...
。。。
Unzipping...
faster_rcnn_models/
faster_rcnn_models/ZF_faster_rcnn_final.caffemodel
faster_rcnn_models/VGG16_faster_rcnn_final.caffemodel

3.编译cython
进入lib目录,修改setup.py,注释掉GPU相关代码,如下

。。。
#CUDA = locate_cuda()

。。。
#            self.set_executable('compiler_so', CUDA['nvcc'])
。。。
#    Extension('nms.gpu_nms',
#        ['nms/nms_kernel.cu', 'nms/gpu_nms.pyx'],
#        library_dirs=[CUDA['lib64']],
#        libraries=['cudart'],
#        language='c++',
#        runtime_library_dirs=[CUDA['lib64']],
#        # this syntax is specific to this build system
#        # we're only going to use certain compiler args with nvcc and not with
#        # gcc the implementation of this trick is in customize_compiler() below
#        extra_compile_args={'gcc': ["-Wno-unused-function"],
#                            'nvcc': ['-arch=sm_35',
#                                     '--ptxas-options=-v',
#                                     '-c',
#                                     '--compiler-options',
#                                     "'-fPIC'"]},
#        include_dirs = [numpy_include, CUDA['include']]
#    ),
。。。

4.编译:
[root@localhost lib]# make

5.安装caffe(自带的,不是通用的)
进入caffe-fast-rcnn目录,大部分跟前面caffe安装记录一文一样,修改Makefile.config(打开WITH_PYTHON_LAYER := 1)

6.修改Makefile

7.编译caffe和pycaffe
[root@localhost caffe-fast-rcnn]# make -j8 && make pycaffe

8.跑demo

[root@localhost py-faster-rcnn]# ./tools/demo.py Traceback (most
recent call last): File “./tools/demo.py”, line 17, in from
fast_rcnn.config import cfg File
“/root/zhanxiang/work/py-faster-rcnn/tools/../lib/fast_rcnn/config.py”,
line 23, in from easydict import EasyDict as edict ImportError: No
module named easydict

缺少Python库easydict,所以安装 pip install easydict

[root@localhost py-faster-rcnn]# ./tools/demo.py Traceback (most
recent call last): File “./tools/demo.py”, line 18, in
from fast_rcnn.test import im_detect File “/root/zhanxiang/work/py-faster-rcnn/tools/../lib/fast_rcnn/test.py”,
line 15, in
import cv2 ImportError: No module named cv2

缺少Python库cv2,这个是openCV里面的。那就来装openCV python库

yum install opencv-python.x86_64

[root@localhost py-faster-rcnn]# python tools/demo.py –cpu Traceback
(most recent call last): File “tools/demo.py”, line 21, in
import matplotlib.pyplot as plt File “/usr/lib64/python2.7/site-packages/matplotlib/pyplot.py”, line 26, in
from matplotlib.figure import Figure, figaspect File “/usr/lib64/python2.7/site-packages/matplotlib/figure.py”, line 36, in
from matplotlib.axes import Axes, SubplotBase, subplot_class_factory File
“/usr/lib64/python2.7/site-packages/matplotlib/axes/init.py”, line
4, in
from ._subplots import * File “/usr/lib64/python2.7/site-packages/matplotlib/axes/_subplots.py”,
line 10, in
from matplotlib.axes._axes import Axes File “/usr/lib64/python2.7/site-packages/matplotlib/axes/_axes.py”, line
14, in
from matplotlib import unpack_labeled_data ImportError: cannot import name unpack_labeled_data

看起来跟matplotlib库有关,pip install的版本太旧,直接下载源码安装。
按照官网指示,http://matplotlib.org/faq/installing_faq.html#install-from-git

[root@localhost work]# git clone git://github.com/matplotlib/matplotlib.git
[root@localhost work]# cd matplotlib/

安装依赖包

[root@localhost matplotlib]# yum-builddep python-matplotlib

安装

[root@localhost matplotlib]# python setup.py install

[

root@localhost py-faster-rcnn]# python tools/demo.py –cpu Traceback
(most recent call last): File “tools/demo.py”, line 19, in
from fast_rcnn.nms_wrapper import nms File “/root/zhanxiang/work/py-faster-rcnn/tools/../lib/fast_rcnn/nms_wrapper.py”,
line 9, in
from nms.gpu_nms import gpu_nms ImportError: No module named gpu_nms

修改nms_wrapper.py,改force_cpu =True

[root@localhost py-faster-rcnn]# vi lib/fast_rcnn/nms_wrapper.py

def nms (dets, thresh, force_cpu =True):
另外把nms_wrapper.py的第9行 from nms.gpu_nms import gpu_nms 注释掉

9.大功告成
[root@localhost py-faster-rcnn]# python tools/demo.py –cpu

参考:
http://blog.sina.com.cn/s/blog_679f93560102wpyf.html

  • 4
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
R-CNN、Fast R-CNNFaster R-CNN是目标检测领域的三个重要算法,用于在图像中检测和定位物体。 1. R-CNN(Region-based Convolutional Neural Networks)是一种基于区域的卷积神经网络方法。它首先在输入图像中生成候选区域,然后对每个候选区域进行卷积特征提取,并使用支持向量机(SVM)进行分类。最后,使用回归器对候选区域进行边界框的微调。R-CNN的主要缺点是速度较慢,因为每个候选区域都需要独立地进行卷积特征提取和分类。 2. Fast R-CNN是对R-CNN的改进。它引入了RoI池化层(Region of Interest pooling),可以在整个图像上共享卷积特征提取,从而大大提高了速度。Fast R-CNN首先对整个图像进行卷积特征提取,然后根据候选区域的位置信息,在卷积特征图上进行RoI池化,将每个候选区域映射为固定大小的特征向量。最后,通过全连接层进行分类和边界框回归。 3. Faster R-CNN是对Fast R-CNN的进一步改进,主要改进了候选区域的生成过程。Faster R-CNN引入了一个称为Region Proposal Network(RPN)的网络,用于生成候选区域。RPN通过在卷积特征图上滑动一个小窗口,预测窗口内是否包含物体以及物体的边界框。然后,这些候选区域被输入到Fast R-CNN中进行分类和边界框回归。Faster R-CNN通过共享卷积特征提取和引入RPN网络,进一步提高了检测速度和准确性。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值