在前一篇随笔中,数据制作成了VOC2007格式,可以用于Faster-RCNN的训练。

1.针对数据的修改

修改datasets\VOCdevkit2007\VOCcode\VOCinit.m,我只做了两类

VOCopts.classes={...
'dog'
'flower'};

修改function\fast_rcnn\fast_rcnn_train.m,val_iters不能大于val数据量(我的只有几十个)。

ip.addParamValue('val_iters',       20,            @isscalar); 

修改function\rpn\proposal_train.m,与上一致。

ip.addParamValue('val_iters',           20,                @isscalar);

修改models\fast_rcnn_prototxts中两个文件夹里面的train_val.prototxt和test.prototxt,以K代表类别数做相应的修改,(共4个文件修改12处)。

input: "bbox_targets"
input_dim: 1 # to be changed on-the-fly to match num ROIs
input_dim: 12 # 4 * (K+1) (=21) classes
input_dim: 1
input_dim: 1 input: "bbox_loss_weights"
input_dim: 1 # to be changed on-the-fly to match num ROIs
input_dim: 12 # 4 * (K+1) (=21) classes
input_dim: 1
input_dim: 1
type: "InnerProduct"
inner_product_param {
num_output: 3 #K+1
weight_filler {
type: "gaussian"
std: 0.01
}
bias_filler {
type: "constant"
value: 0
}
}
layer {
bottom: "fc7"
top: "cls_score"
name: "cls_score"
param {
lr_mult: 1.0
}
param {
lr_mult: 2.0
}
type: "InnerProduct"
inner_product_param {
num_output: 3 # K+1
weight_filler {
type: "gaussian"
std: 0.01
}
bias_filler {
type: "constant"
value: 0
}
}
} layer {
bottom: "fc7"
top: "bbox_pred"
name: "bbox_pred"
type: "InnerProduct"
param {
lr_mult: 1.0
}
param {
lr_mult: 2.0
}
inner_product_param {
num_output: 12 # 4 * (K+1)
weight_filler {
type: "gaussian"
std: 0.001
}
bias_filler {
type: "constant"
value: 0
}
}
}

修改experiments\+Model\ZF_for_Faster_RCNN_VOC2007.m的三个为solver_30k40k.prototxt,默认60k80k所需时间过长。

2.根据设备性能的修改

显卡GTX750,显存2G,尽管数据不多,在默认设置下出现了内存不够的错误。

修改functions\fast_rcnn\fast_rcnn_config.m,以%标注的为默认值。

%% training
% whether use gpu
ip.addParamValue('use_gpu', gpuDeviceCount > 0, ...
@islogical);
% Image scales -- the short edge of input image
ip.addParamValue('scales', 60, @ismatrix); %600
% Max pixel size of a scaled input image
ip.addParamValue('max_size', 1000, @isscalar);
% Images per batch
ip.addParamValue('ims_per_batch', 2, @isscalar);
% Minibatch size
ip.addParamValue('batch_size', 32, @isscalar); %128
% Fraction of minibatch that is foreground labeled (class > 0)
ip.addParamValue('fg_fraction', 0.25, @isscalar);
% Overlap threshold for a ROI to be considered foreground (if >= fg_thresh)
ip.addParamValue('fg_thresh', 0.5, @isscalar);
% Overlap threshold for a ROI to be considered background (class = 0 if
% overlap in [bg_thresh_lo, bg_thresh_hi))
ip.addParamValue('bg_thresh_hi', 0.5, @isscalar);
ip.addParamValue('bg_thresh_lo', 0.1, @isscalar);
% mean image, in RGB order
ip.addParamValue('image_means', 128, @ismatrix);
% Use horizontally-flipped images during training?
ip.addParamValue('use_flipped', true, @islogical);
% Vaild training sample (IoU > bbox_thresh) for bounding box regresion
ip.addParamValue('bbox_thresh', 0.5, @isscalar); % random seed
ip.addParamValue('rng_seed', 6, @isscalar); %% testing
ip.addParamValue('test_scales', 60, @isscalar); %600
ip.addParamValue('test_max_size', 1000, @isscalar);
ip.addParamValue('test_nms', 0.3, @isscalar);
ip.addParamValue('test_binary', false, @islogical);

3.开始训练

训练前删除或备份output,imdb\cache,运行experiments/script_faster_rcnn_VOC2007_ZF.m 开始训练。

在我的显卡上经过四个小时,训练完成。

下面是未删除output重新运行(很快)的结果。

***************
stage one proposal
***************
aver_boxes_num = 1090, select top 2000
aver_boxes_num = 1091, select top 2000 ***************
stage one fast rcnn
***************
!!! dog : 0.8969 0.9418
!!! flower : 0.9006 0.9458 ~~~~~~~~~~~~~~~~~~~~
Results:
89.6920
90.0606 89.8763 ~~~~~~~~~~~~~~~~~~~~ ***************
stage two proposal
***************
aver_boxes_num = 1263, select top 2000
aver_boxes_num = 1271, select top 2000 ***************
stage two fast rcnn
*************** ***************
final test
***************
aver_boxes_num = 233, select top 300
!!! dog : 0.8893 0.9449
!!! flower : 0.8990 0.9445 ~~~~~~~~~~~~~~~~~~~~
Results:
88.9304
89.9025 89.4165 ~~~~~~~~~~~~~~~~~~~~
Cleared 0 solvers and 2 stand-alone nets
please modify detection_test.prototxt file for sharing conv layers with proposal model (delete layers until relu5)
>>

4.测试

训练结束已有提示,要先修改detection_test.prototxt。

修改data为1*256*50*50,去掉roi_pool5之前的layer并将bottom改为data。

name: "Zeiler_conv5"

input: "data"
input_dim: 1
input_dim: 256
input_dim: 50
input_dim: 50 input: "rois"
input_dim: 1 # to be changed on-the-fly to num ROIs
input_dim: 5 # [batch ind, x1, y1, x2, y2] zero-based indexing
input_dim: 1
input_dim: 1 layer {
bottom: "data"
bottom: "rois"
top: "pool5"
name: "roi_pool5"
type: "ROIPooling"
roi_pooling_param {
pooled_w: 6
pooled_h: 6
spatial_scale: 0.0625 # (1/16)
}
}

在experiments\script_faster_rcnn_demo.m中将路径更改成本地相应路径,根据测试结果可以修改thres值。

model_dir                   = fullfile(pwd, 'output', 'faster_rcnn_final', 'faster_rcnn_VOC2007_ZF'); %% ZF_test
im_names = {'000001.jpg','000002.jpg','000034.jpg','000212.jpg','000213.jpg', '001150.jpg'};
thres = 0.3;  %0.6

检测速度很快,不过此次我的数据检测效果很不好,可能由于数据太少、画框不认真或某些没有意识到的参数错误-_-!。

Faster-RCNN 训练自己的数据的更多相关文章

  1. caffe学习三:使用Faster RCNN训练自己的数据

    本文假设你已经完成了安装,并可以运行demo.py 不会安装且用PASCAL VOC数据集的请看另来两篇博客. caffe学习一:ubuntu16.04下跑Faster R-CNN demo (基于c ...

  2. python3 + Tensorflow + Faster R-CNN训练自己的数据

    之前实现过faster rcnn, 但是因为各种原因,有需要实现一次,而且发现许多博客都不全面.现在发现了一个比较全面的博客.自己根据这篇博客实现的也比较顺利.在此记录一下(照搬). 原博客:http ...

  3. caffe 用faster rcnn 训练自己的数据 遇到的问题

    1 . 怎么处理那些pyx和.c .h文件 在lib下有一些文件为.pyx文件,遇到不能import可以cython 那个文件,然后把lib文件夹重新make一下. 遇到.c 和 .h一样的操作. 2 ...

  4. 如何才能将Faster R-CNN训练起来?

    如何才能将Faster R-CNN训练起来? 首先进入 Faster RCNN 的官网啦,即:https://github.com/rbgirshick/py-faster-rcnn#installa ...

  5. faster rcnn训练详解

    http://blog.csdn.net/zy1034092330/article/details/62044941 py-faster-rcnn训练自己的数据:流程很详细并附代码 https://h ...

  6. faster rcnn 源码学习-------数据读入及RoIDataLayer相关模块解读

    参考博客:::https://www.cnblogs.com/Dzhen/p/6845852.html 非常全面的解读参考:::https://blog.csdn.net/DaVinciL/artic ...

  7. faster rcnn训练自己的数据集

    采用Pascal VOC数据集的组织结构,来构建自己的数据集,这种方法是faster rcnn最便捷的训练方式

  8. Faster Rcnn训练自己的数据集过程大白话记录

    声明:每人都有自己的理解,动手实践才能对细节更加理解! 一.算法理解 此处省略一万字.................. 二.训练及源码理解 首先配置: 在./lib/utils文件下....运行 p ...

  9. Faster RCNN 运行自己的数据,刚开始正常,后来就报错: Index exceeds matrix dimensions. Error in ori_demo (line 114) boxes_cell{i} = [boxes(:, (1+(i-1)*4):(i*4)), scores(:, i)];

    function script_faster_rcnn_demo() close all; clc; clear mex; clear is_valid_handle; % to clear init ...

  10. faster rcnn训练过程讲解

    http://blog.csdn.net/u014696921/article/details/60321425

随机推荐

  1. JavaScript学习笔记及知识点整理_3

    1.js的事件冒泡及阻止方法:事件冒泡的概念:在一个对象上触发某类事件(比如单击onclick事件),如果此对象定义了此事件的处理程序,那么此事件就会调用这个处理程序,如果没有定义此事件处理程序或者事 ...

  2. (七)HTTP协议

    HTTP协议报文基本格式 HTTP协议报文基本格式       HTTP协议(Hypertext Transfer Protocol――超文本传输协议),浏览器端(客户端)向WEB服务器端访问页面的过 ...

  3. jquery 返回上一页 ,关闭js代码

    1.关闭功能: $(“#guanbi”).live("click",function()){ window.close(); } 2.返回上一页: <a href=" ...

  4. 【xsy1019】小A的树论

    题意 三种操作: ①区间增值 ②某一个点换父亲 ③求子树和 \(1\leq n\leq 100000\) 分析 Splay维护dfn序. 小结 (1)使用Splay,通常要在Splay的两端各添加一个 ...

  5. 《Java虚拟机并发编程》学习笔记

    对<Java虚拟机并发编程>这本书真的是相见恨晚.以前对并发编程只是懂个皮毛,这本书让我对并发编程有了一个全新的认识.所以把书上的知识点做下笔记,以便以后复习使用. 并发与并行 仔细说来, ...

  6. windows添加虚拟网卡

  7. CSS3判断手机横屏竖屏

    原理: 当用户旋转屏幕的时候,会进入到你的监听方法中,然后通过window.orientation来获取当前屏幕的状态:0 - 竖屏90 - 逆时针旋转横屏-90 - 顺时针旋转横屏180 - 竖屏, ...

  8. nulls last ratio_to_report(id) over() 占比函数

     ORDER BY t3.pctl DESC NULLS LAST http://blog.itpub.net/9932141/viewspace-600751/ http://blog.csdn.n ...

  9. JavaEE 7技术一览

    参见此文: https://my.oschina.net/Barudisshu/blog/334903 perfect

  10. BestCoder Round #39

    -------好久没更新博客了,发现还是需要不断总结才能进步,所以还是把最近打的一些比赛记录一下. T1:Delete (hdu 5210) 题目大意: 给出n个数,然后要删掉k个,要求剩下的数中 不 ...