Ubuntu下运行Faster-Rcnn

来源:互联网 发布:js设置属性值 编辑:程序博客网 时间:2024/05/17 06:49

转载自:http://blog.csdn.net/qq_30040223/article/details/48491997

Ubuntu下运行Faster-Rcnn

Faster-Rcnn 介绍

前几天Shaoqing Ren放出了Faster-Rcnn的代码,可以在他的Github上下载得到,上面也有详细的配置说明。
我下载下来,在自己的虚拟机上测试了一下,速度上确实比之前的Fast-Rcnn有提高。

SPP-Net,Fast-Rcnn,Faster-Rcnn都是在Ross Girshick2014年发布的RCNN上面的改进与提高,其中SPP-Net,Faster-Rcnn都是Shaoqing Ren的作品,当然其中还有Kaiming He以及Ross Girshick等微软亚研院研究员的贡献。Shaoqing Ren也是个牛人啊,可以去他的个人主页看看他做的一些工作,ICCV,CVPR,ECCV三大会,PAMI都发过论文,今年Faster-Rcnn还发表在了NIPS上,是我的奋斗目标!

Faster-Rcnn相对于Fast-Rcnn的改进在于将Object Proposal利用CNN网络实现,并与Detection的CNN网络结合实现了一个端到端的Object Detection框架。之前Fast-Rcnn的Proposal是利用Selective Search实现的,SS方法虽然得到的Proposal相对于其他方法是较好的,但是其速度比较慢,更不用说跟利用GPU进行加速的Detection步骤相比,由此Proposal的产生便成为了一个瓶颈。

而Faster-Rcnn便解决了这个问题,不单单是加速了Proposal的产生,还将两个网络结合进行优化,于是原本跟Detection任务分离的Proposal步骤被结合了起来,Detection的结果好坏会通过梯度的回传影响到Proposal网络的参数,Faster-Rcnn实现优化的思路采用的是常见的固定一个更新另一个的策略,固定Proposal网络,更新Detection网络,再固定Detection网络,更新Proposal网络。

Faster-Rcnn 配置

参考Shaoqing Ren的配置说明:

(1) 安装Matlab 2014a
(2) 下载源代码

git clone --recursive https://github.com/ShaoqingRen/faster_rcnn.git

(3)配置Caffe
将你之前配置过的CaffeMakefile.config拷贝至./faster-rcnn/external/caffe,记得修改Matlab接口,接着编译就可以了。

make -j$(nproc)make matcaffe -j$(nproc)

(4) 运行Faster-Rcnn
A. 在faster-rcnn路径下打开Matlab,或者直接打开Matlab再切换到faster-rcnn路径,运行faster_rcnn_build.m,没有GPU的话在Compiling nms_gpu_mex时会出错,但其他是能够正常编译的,所以没有关系。
B. 运行startup.m,会加入其所需路径。
C. 运行fetch_data/fetch_faster_rcnn_final_model.m,下载所需模型。推荐在作者Github上找百度云盘的下载链接,速度会快上不少,下载完将output文件夹解压至./faster-rcnn目录下。
D. 打开experiments/script_faster_rcnn_demo.m测试文件,没有GPU不要直接运行,其代码默认是用GPU进行测试的,因此在CPU模式下会出错。
修改下代码,不使用GPU即可:
修改前:

%% -------------------- CONFIG --------------------opts.caffe_version          = 'caffe_faster_rcnn';opts.gpu_id                 = auto_select_gpu;active_caffe_mex(opts.gpu_id, opts.caffe_version);opts.per_nms_topN           = 6000;opts.nms_overlap_thres      = 0.7;opts.after_nms_topN         = 300;opts.use_gpu                = True;opts.test_scales            = 600;

修改后:

%% -------------------- CONFIG --------------------opts.caffe_version          = 'caffe_faster_rcnn';%opts.gpu_id                 = auto_select_gpu;%active_caffe_mex(opts.gpu_id, opts.caffe_version);opts.per_nms_topN           = 6000;opts.nms_overlap_thres      = 0.7;opts.after_nms_topN         = 300;opts.use_gpu                = false;opts.test_scales            = 600;

E.运行该测试文件
默认载入的模型是VGG16网络,如果运行过程中出现kill,那就把模型换成ZF的好了。
VGG16网络比较大,可能会出现内存不足,所以在虚拟机或者内存较小的机器上推荐使用小模型ZF来进行测试。

%% -------------------- INIT_MODEL --------------------%model_dir = fullfile(pwd, 'output', 'faster_rcnn_final', 'faster_rcnn_VOC0712_vgg_16layers'); %% VGG-16model_dir  = fullfile(pwd, 'output', 'faster_rcnn_final', 'faster_rcnn_VOC0712_ZF'); %% ZFproposal_detection_model    = load_proposal_detection_model(model_dir);

F.测试结果
我的CPU是I5-4460,测试速度是比Fast-Rcnn更快的。

fast_rcnn startup done001763.jpg (500x375): time 3.675s (resize+conv+proposal: 2.754s, nms+regionwise: 0.921s)004545.jpg (500x375): time 4.640s (resize+conv+proposal: 2.887s, nms+regionwise: 1.753s)000542.jpg (500x375): time 3.654s (resize+conv+proposal: 3.019s, nms+regionwise: 0.634s)000456.jpg (500x375): time 4.502s (resize+conv+proposal: 2.959s, nms+regionwise: 1.543s)001150.jpg (500x375): time 4.026s (resize+conv+proposal: 2.930s, nms+regionwise: 1.097s)mean time: 4.099sCleared 0 solvers and 2 stand-alone nets

这里写图片描述
这里写图片描述

0 0
原创粉丝点击