http://blog.csdn.net/happyflyy/article/details/54917514
注意:整個RPN完全是筆者自己的理解,可能會有一些理解錯誤的地方。
1. RPN簡介
RPN是regional proposal networks的縮寫,是faster-RCNN結構中的一部分。faster-RCNN由兩個子網絡構成。第一個子網絡RPN的作用是在給定圖像上提取一定數量帶有objectness(是否包含目標的置信度)。第二個子網絡直接利用fast-rcnn中的特征提取網絡,用RPN獲得的proposal替代fast-RCNN中selective search獲取的proposal。
2. RPN的結構
RPN的原理圖如下圖所示。
RPN的結構是在已有的網路結構(例如VGG)的最后一層上添加如下圖的新層。以VGG為例,下圖中每部分的具體結構為:
1. conv feature map:在VGG的conv5_3后新添加的一個512@3x3的卷基層。
2. k anchor boxes:在每個sliding window的點上的初始化的參考區域。每個sliding window的點上取得anchor boxes都一樣。只要知道sliding window的點的坐標,就可以計算出每個anchor box的具體坐標。faster-RCNN中k=9,先確定一個base anchor,大小為16×16,保持面積不變使其長寬比為(0.5,1,2),再對這三個不同長寬比的anchor放大(8,16,32)三個尺度,一共得到9個anchors。
3. intermediate layer:作者代碼中並沒有這個輸出256d特征的中間層,直接通過1×1的卷積獲得2k scores和4k cordinates。作者在文中解釋為用全卷積方式替代全連接。
4. 2k scores:對於每個anchor,用了softmax layer的方式,會或得兩個置信度。作者在文中說也可以用sigmoid方式獲得一維是正例的置信度。
5. 4k cordinates:每個窗口的坐標。這個坐標並不是anchor的絕對坐標,而是通過anchor回歸groundtruth的位置所需要的偏差(會在下一節具體介紹)。
對於一幅大小為600×800的圖像,通過VGG之后,conv5_3的大小為38×50,則總的anchor的個數為38×50×9。
3. 通過代碼理解RPN
運行代碼環境:Ubuntu14.04,MatlabR2016a。
1 准備
假設已經安裝好caffe所需要的依賴庫,faster-RCNN中有caffe的matlab接口,所以不需要安裝編譯caffe。以PASCAL VOC0712為例:
Step1: 下載faster-RCNN的源代碼並解壓。下載地址為https://github.com/ShaoqingRen/faster_rcnn。假設解壓之后路徑為$FASTERRCNN/
。
Step2:下載VOC07和VOC12並解壓到任意文件夾(最好解壓到$FASTERRCNN/datasets/
)。
Step3:下載網絡模型文件以及預訓練的VGG,解壓后拷貝到$FASTERRCNN/
。下載地址為https://pan.baidu.com/s/1mgzSnI4。
Step4:在shell中進入$FASTERRCNN/
並運行matlab。
2 faster-RCNN的文件結構
經過上面的准備之后,matlab中faster-RCNN的文件結構如下圖所示:
./bin:./functions/nms中非極大值抑制(NMS)的c代碼mex之后的文件
./datasets:VOC數據集的存放路徑
./experimenet:訓練或者測試的入口函數
./external:caffe的matlab接口。只需安裝好caffe的依賴庫,並不需要編譯caffe源文件。
./fetch_date:下載數據集,預訓練模型等文件的函數
./functions:訓練數據處理相關的函數
./imdb:將VOC數據讀入到imdb格式
./models:基網絡(如VGG)的預訓練模型;fast-RCNN,RPN網絡結構prototxt及求解相關的參數prototxt文件
./utils:一些其它常用的函數
注意:./test是筆者在運行測試demo時臨時存放的一些測試圖像,和faster-RCNN並沒有什么關系。
3 訓練過程
采用VGG和VOC0712,其對應的訓練文件為$FASTERRCNN/experiments/script_faster_rcnn_VOC0712_VGG16.m。由於只理解RPN部分,所以只需要詳細了解這個m文件的前一小部分。
% code from $FASTERRCNN/experiments/script_faster_rcnn_VOC0712_VGG16.m % % model model = Model.VGG16_for_Faster_RCNN_VOC0712; % cache base cache_base_proposal = 'faster_rcnn_VOC0712_vgg_16layers'; cache_base_fast_rcnn = ''; % train/test data dataset = []; use_flipped = true; dataset = Dataset.voc0712_trainval(dataset, 'train', use_flipped); dataset = Dataset.voc2007_test(dataset, 'test', false); %% -------------------- TRAIN -------------------- % conf conf_proposal = proposal_config('image_means', model.mean_image, 'feat_stride', model.feat_stride); conf_fast_rcnn = fast_rcnn_config('image_means', model.mean_image); % set cache folder for each stage model = Faster_RCNN_Train.set_cache_folder(cache_base_proposal, cache_base_fast_rcnn, model); % generate anchors and pre-calculate output size of rpn network [conf_proposal.anchors, conf_proposal.output_width_map, conf_proposal.output_height_map] ... = proposal_prepare_anchors(conf_proposal, model.stage1_rpn.cache_name, model.stage1_rpn.test_net_def_file); %% stage one proposal fprintf('\n***************\nstage one proposal \n***************\n'); % train model.stage1_rpn = Faster_RCNN_Train.do_proposal_train(conf_proposal, dataset, model.stage1_rpn, opts.do_val);
1參數配置階段
RPN
一共配置了三個參數model
,dataset
,conf_proposal
。conf_fast_rcnn
是fast-RCNN的參數。
1 model參數:
指定了RPN和fast-RCNN兩個階段所需要的網絡結構配置文件prototxt的路徑。通過第一階段的RPN熟悉其具體過程。
指定了VGG pre-trained模型及圖像均值的路徑。
參數model
的配置:
% code from $FASTERRCNN/experiments/script_faster_rcnn_VOC0712_VGG16.m % % model model = Model.VGG16_for_Faster_RCNN_VOC0712;```
具體配置程序為下面的代碼片段,只關注RPN第一階段相關的代碼。首先指定了基網絡(VGG)預訓練模型和圖像均值文件路徑;然后指定了RPN相關prototxt文件路徑;最后設置了RPN測試參數。
% code from $FASTERRCNN/experiments/+Model/VGG16_for_faster_RCNN_VOC0712.m % % 基網絡(VGG)預訓練模型和圖像均值文件路徑 model.mean_image = fullfile(pwd, 'models', 'pre_trained_models', 'vgg_16layers', 'mean_image'); model.pre_trained_net_file = fullfile(pwd, 'models', 'pre_trained_models', 'vgg_16layers', 'vgg16.caffemodel'); % Stride in input image pixels at the last conv layer model.feat_stride = 16; % RPN相關prototxt文件路徑 %% stage 1 rpn, inited from pre-trained network model.stage1_rpn.solver_def_file = fullfile(pwd, 'models', 'rpn_prototxts', 'vgg_16layers_conv3_1', 'solver_60k80k.prototxt'); model.stage1_rpn.test_net_def_file = fullfile(pwd, 'models', 'rpn_prototxts', 'vgg_16layers_conv3_1', 'test.prototxt'); model.stage1_rpn.init_net_file = model.pre_trained_net_file; % RPN測試參數 % rpn test setting model.stage1_rpn.nms.per_nms_topN = -1; model.stage1_rpn.nms.nms_overlap_thres = 0.7; model.stage1_rpn.nms.after_nms_topN = 2000;
2 dataset參數:
修改數據集路徑
如果VOC數據沒有解壓在$FASTERRCNN/datasets/
文件夾中,更改 $ FASTERRCNN/experiments/+Dataset/private/voc2007_devkit.m
和$FASTERRCNN/experiments/+Dataset/private/voc2012_devkit.m
中的路徑為VOC數據集的解壓路徑。
% code from `$FASTERRCNN/experiments/+Dataset/private/voc2007_devkit.m` % function path = voc2007_devkit() path = './datasets/VOCdevkit2007'; end
% code from `$FASTERRCNN/experiments/+Dataset/private/voc2012_devkit.m` % function path = voc2012_devkit() path = './datasets/VOCdevkit2012'; end
dataset參數
參數dataset
的配置:
% code from $FASTERRCNN/experiments/script_faster_rcnn_VOC0712_VGG16.m % % train/test data dataset = []; use_flipped = true; dataset = Dataset.voc0712_trainval(dataset, 'train', use_flipped); dataset = Dataset.voc2007_test(dataset, 'test', false);
具體實現數據集讀取的文件為 $FASTERRCNN/experiments/+Dataset/voc0712_trainval.m
和$FASTERRCNN/experiments/+Dataset/voc0712_test
。首先獲得數據集存儲路徑;然后將數據讀入到imdb和roidb文件。
% code from $FASTERRCNN/experiments/+Dataset/voc0712_trainval.m % % 獲得數據集存儲路徑 devkit2007 = voc2007_devkit(); devkit2012 = voc2012_devkit(); % 將數據讀入到imdb和roidb文件 switch usage case {'train'} dataset.imdb_train = { imdb_from_voc(devkit2007, 'trainval', '2007', use_flip), ... imdb_from_voc(devkit2012, 'trainval', '2012', use_flip)}; dataset.roidb_train = cellfun(@(x) x.roidb_func(x), dataset.imdb_train, 'UniformOutput', false); case {'test'} error('only supports one source test currently'); otherwise error('usage = ''train'' or ''test'''); end
imdb文件是一個matlab的表結構,表的每一行是一幅圖像,分別包含如下信息:圖像的路徑,編號,大小,groundtruth(位置及類標)等。
3 conf_proposal參數:
只關注RPN的conf_proposal
% code from $FASTERRCNN/experiments/script_faster_rcnn_VOC0712_VGG16.m % % conf conf_proposal = proposal_config('image_means', model.mean_image, 'feat_stride', model.feat_stride);
RPN所需要的參數。其中值得注意的參數有
batch_size:[256]每幅圖像中篩選使用的bg樣本和fg樣本的總個數
fg_fraction:[0.5]batch_size中fg樣本的比例,如果fg樣本個數不足,則添加bg樣本
drop_boxes_runoff_image:[1]在訓練階段是否去掉超出圖像邊界的anchors
bg_thresh_hi:[0.3]被看做反例樣本的anchor與groundtruth的最大IoU
bg_thresh_lo:[0]被看做反例樣本的anchor與groundtruth的最小IoU
fg_thresh:[0.7]被看做正例樣本的anchor與groundtruth的最小IoU
ims_per_batch:[1]訓練時每次輸入的圖像個數,當前只支持每次輸入一幅圖像
scale:[600]短邊縮放后最小值
max_size:[1000]長邊縮放后最大值
feat_stride:[16]VGG中conv5_3相比於輸入圖像縮小了16倍,也就是相鄰兩個點之間的stride=16
anchors:不同長寬比和尺度的9個基本anchors
output_width_map:輸入圖像的寬度和conv5_3寬度的對應關系
output_height_map:輸入圖像的高度和conv5_3高度的對應關系
bg_weight:[1]計算損失時每個反例樣本的權值,正例樣本權值全為1
image_means: 圖像均值
具體配置文件為:
% code from $FASTERRCNN/functions/rpn/proposal_config.m % function conf = proposal_config(varargin) % conf = proposal_config(varargin) % -------------------------------------------------------- % Faster R-CNN % Copyright (c) 2015, Shaoqing Ren % Licensed under The MIT License [see LICENSE for details] % -------------------------------------------------------- ip = inputParser; %% training ip.addParamValue('use_gpu', gpuDeviceCount > 0, ... @islogical); % whether drop the anchors that has edges outside of the image boundary ip.addParamValue('drop_boxes_runoff_image', ... true, @islogical); % Image scales -- the short edge of input image ip.addParamValue('scales', 600, @ismatrix); % Max pixel size of a scaled input image ip.addParamValue('max_size', 1000, @isscalar); % Images per batch, only supports ims_per_batch = 1 currently ip.addParamValue('ims_per_batch', 1, @isscalar); % Minibatch size ip.addParamValue('batch_size', 256, @isscalar); % Fraction of minibatch that is foreground labeled (class > 0) ip.addParamValue('fg_fraction', 0.5, @isscalar); % weight of background samples, when weight of foreground samples is % 1.0 ip.addParamValue('bg_weight', 1.0, @isscalar); % Overlap threshold for a ROI to be considered foreground (if >= fg_thresh) ip.addParamValue('fg_thresh', 0.7, @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.3, @isscalar); ip.addParamValue('bg_thresh_lo', 0, @isscalar); % mean image, in RGB order ip.addParamValue('image_means', 128, @ismatrix); % Use horizontally-flipped images during training? ip.addParamValue('use_flipped', true, @islogical); % Stride in input image pixels at ROI pooling level (network specific) % 16 is true for {Alex,Caffe}Net, VGG_CNN_M_1024, and VGG16 ip.addParamValue('feat_stride', 16, @isscalar); % train proposal target only to labled ground-truths or also include % other proposal results (selective search, etc.) ip.addParamValue('target_only_gt', true, @islogical); % random seed ip.addParamValue('rng_seed', 6, @isscalar); %% testing ip.addParamValue('test_scales', 600, @isscalar); ip.addParamValue('test_max_size', 1000, @isscalar); ip.addParamValue('test_nms', 0.3, @isscalar); ip.addParamValue('test_binary', false, @islogical); ip.addParamValue('test_min_box_size',16, @isscalar); ip.addParamValue('test_drop_boxes_runoff_image', ... false, @islogical); ip.parse(varargin{:}); conf = ip.Results; assert(conf.ims_per_batch == 1, 'currently rpn only supports ims_per_batch == 1'); % if image_means is a file, load it if ischar(conf.image_means) s = load(conf.image_means); s_fieldnames = fieldnames(s); assert(length(s_fieldnames) == 1); conf.image_means = s.(s_fieldnames{1}); end end
2 產生anchor
% code from $FASTERRCNN/experiments/script_faster_rcnn_VOC0712_VGG16.m
%
% generate anchors and pre-calculate output size of rpn network
[conf_proposal.anchors, conf_proposal.output_width_map, conf_proposal.output_height_map] ... = proposal_prepare_anchors(conf_proposal, model.stage1_rpn.cache_name, model.stage1_rpn.test_net_def_file);
proposal_prepare_anchors
函數分為兩部分。首先產生輸入圖像大小和conv5_3大小的對應關系map;然后產生9個基本anchors。最后將output_width_map
,output_height_map
以及anchors
存入conf_proposal
參數中。
% code from $FASTERRCNN/experiments/script_faster_rcnn_VOC0712_VGG16.m
%
function [anchors, output_width_map, output_height_map] = proposal_prepare_anchors(conf, cache_name, test_net_def_file) %產生輸入圖像大小和conv5_3大小的對應關系 [output_width_map, output_height_map] ... = proposal_calc_output_size(conf, test_net_def_file); %產生9個基本anchors anchors = proposal_generate_anchors(cache_name, ... 'scales', 2.^[3:5]); end
1 輸入圖像大小和conv5_3大小的對應關系
首先初始化RPN的測試網絡;然后產生不同長寬的全零圖像並進行前向傳播;記錄每個輸入圖像大小對應的conv5_3大小;重置caffe。
% code from $FASTERRCNN/functions/rpn/proposal_calc_output_size.m % % 初始化RPN的測試網絡 caffe_net = caffe.Net(test_net_def_file, 'test'); % set gpu/cpu if conf.use_gpu caffe.set_mode_gpu(); else caffe.set_mode_cpu(); end % 產生不同長寬的全零圖像並進行前向傳播 input = 100:conf.max_size; output_w = nan(size(input)); output_h = nan(size(input)); for i = 1:length(input) s = input(i); im_blob = single(zeros(s, s, 3, 1)); net_inputs = {im_blob}; % Reshape net's input blobs caffe_net.reshape_as_input(net_inputs); caffe_net.forward(net_inputs); % 記錄每個輸入圖像大小對應的conv5_3大小 cls_score = caffe_net.blobs('proposal_cls_score').get_data(); output_w(i) = size(cls_score, 1); output_h(i) = size(cls_score, 2); end output_width_map = containers.Map(input, output_w); output_height_map = containers.Map(input, output_h); % 重置caffe caffe.reset_all();
2 生成9個基准anchors
設置最基准的anchor大小為16×16;保持面積不變,利用該m文件中ratio_jitter
生成三個長寬比(0.5,1,2)的anchors,如下圖所示;通過該m文件中scale_jitter
將不同長寬比的anchors放大到三個尺度(8,16,32)。一共生成9個anchors。
% code from $FASTERRCNN/functions/rpn/proposal_generate_anchors.m % %% inputs ip = inputParser; ip.addRequired('cache_name', @isstr); % the size of the base anchor ip.addParamValue('base_size', 16, @isscalar); % ratio list of anchors ip.addParamValue('ratios', [0.5, 1, 2], @ismatrix); % scale list of anchors ip.addParamValue('scales', 2.^[3:5], @ismatrix); ip.addParamValue('ignore_cache', false, @islogical); ip.parse(cache_name, varargin{:}); opts = ip.Results; %% if ~opts.ignore_cache anchor_cache_dir = fullfile(pwd, 'output', 'rpn_cachedir', cache_name); mkdir_if_missing(anchor_cache_dir); anchor_cache_file = fullfile(anchor_cache_dir, 'anchors'); end try ld = load(anchor_cache_file); anchors = ld.anchors; catch % 設置最基准的anchor大小為$16\times16$ base_anchor = [1, 1, opts.base_size, opts.base_size]; % 保持面積不變,生成不同長寬比的anchors ratio_anchors = ratio_jitter(base_anchor, opts.ratios); % 在不同長寬比anchors的基礎上進行尺度縮放 anchors = cellfun(@(x) scale_jitter(x, opts.scales), num2cell(ratio_anchors, 2), 'UniformOutput', false); anchors = cat(1, anchors{:}); if ~opts.ignore_cache save(anchor_cache_file, 'anchors'); end end
3 訓練階段
所有參數設置完成后開始訓練。
% code from $FASTERRCNN/experiments/script_faster_rcnn_VOC0712_VGG16.m % %% stage one proposal fprintf('\n***************\nstage one proposal \n***************\n'); % train model.stage1_rpn = Faster_RCNN_Train.do_proposal_train(conf_proposal, dataset, model.stage1_rpn, opts.do_val);
do_proposal_train
直接調用$FASTERRCNN/functions/rpn/proposal_train.m
文件。
根據作者注釋的流程,$FASTERRCNN/functions/rpn/proposal_train.m
主要分為init
, making tran/val data
和Training
三個階段
1 init
,初始化
初始化中主要設置緩存文件路徑,讀入caffe求解參數,讀入caffe模型結構,讀入預訓練模型,初始化日志文件,設置GPU模式。
% code from `$FASTERRCNN/functions/rpn/proposal_train.m` % %% init % init caffe solver imdbs_name = cell2mat(cellfun(@(x) x.name, imdb_train, 'UniformOutput', false)); cache_dir = fullfile(pwd, 'output', 'rpn_cachedir', opts.cache_name, imdbs_name); mkdir_if_missing(cache_dir); caffe_log_file_base = fullfile(cache_dir, 'caffe_log'); caffe.init_log(caffe_log_file_base); caffe_solver = caffe.Solver(opts.solver_def_file); caffe_solver.net.copy_from(opts.net_file); % init log timestamp = datestr(datevec(now()), 'yyyymmdd_HHMMSS'); mkdir_if_missing(fullfile(cache_dir, 'log')); log_file = fullfile(cache_dir, 'log', ['train_', timestamp, '.txt']); diary(log_file); % set random seed prev_rng = seed_rand(conf.rng_seed); caffe.set_random_seed(conf.rng_seed); % set gpu/cpu if conf.use_gpu caffe.set_mode_gpu(); else caffe.set_mode_cpu(); end disp('conf:'); disp(conf); disp('opts:'); disp(opts);
2 making tran/val data,將bbs的數據轉換為regression的數據
% code from `$FASTERRCNN/functions/rpn/proposal_train.m`
%
%% making tran/val data
fprintf('Preparing training data...'); [image_roidb_train, bbox_means, bbox_stds]... = proposal_prepare_image_roidb(conf, opts.imdb_train, opts.roidb_train); fprintf('Done.\n'); if opts.do_val fprintf('Preparing validation data...'); [image_roidb_val]... = proposal_prepare_image_roidb(conf, opts.imdb_val, opts.roidb_val, bbox_means, bbox_stds); fprintf('Done.\n');
proposal_prepare_image_roidb.m
從imdb以及roidb中讀入圖像信息后,實現了:圖像中bbx的groundtruth數據由[x1,y1,x2,y2]轉換為[dx,dy,dw,dh],由faster-RCNN論文中的公式(2)實現;然后對bg和fg樣本進行篩選;最后計算轉換后的[dx,dy,dw,dh]均值和方差。
Step1: 從imdb以及roidb中讀入圖像信息
% code from `$FASTERRCNN/functions/rpn/proposal_prepare_image_roidb.m`
%
imdbs = imdbs(:);
roidbs = roidbs(:);
if conf.target_only_gt image_roidb = ... cellfun(@(x, y) ... // @(imdbs, roidbs) arrayfun(@(z) ... //@([1:length(x.image_ids)]) struct('image_path', x.image_at(z), 'image_id', x.image_ids{z}, 'im_size', x.sizes(z, :), 'imdb_name', x.name, 'num_classes', x.num_classes, ... 'boxes', y.rois(z).boxes(y.rois(z).gt, :), 'class', y.rois(z).class(y.rois(z).gt, :), 'image', [], 'bbox_targets', []), ... [1:length(x.image_ids)]', 'UniformOutput', true),... imdbs, roidbs, 'UniformOutput', false); else image_roidb = ... cellfun(@(x, y) ... // @(imdbs, roidbs) arrayfun(@(z) ... //@([1:length(x.image_ids)]) struct('image_path', x.image_at(z), 'image_id', x.image_ids{z}, 'im_size', x.sizes(z, :), 'imdb_name', x.name, ... 'boxes', y.rois(z).boxes, 'class', y.rois(z).class, 'image', [], 'bbox_targets', []), ... [1:length(x.image_ids)]', 'UniformOutput', true),... imdbs, roidbs, 'UniformOutput', false); end image_roidb = cat(1, image_roidb{:});
Step2: bbx的groundtruth轉換
% code from `$FASTERRCNN/functions/rpn/proposal_prepare_image_roidb.m` % % enhance roidb to contain bounding-box regression targets [image_roidb, bbox_means, bbox_stds] = append_bbox_regression_targets(conf, image_roidb, bbox_means, bbox_stds);
proposal_prepare_image_roidb.m
,詳細步驟為:
- 讀入圖像信息:將圖像信息讀入到image_roidb
中。
- groundtruth數據轉換:proposal_prepare_image_roidb.m
中的append_bbox_regression_targets
實現
- 獲得所有anchors:通過proposal_locate_anchors.m
獲得圖像的所有anchors以及圖像需要縮放的比例
- 圖像縮放比例:通過scale
和max_size
獲得圖像的縮放比例並記錄縮放后圖像大小
圖像的最短邊最小值為scale
,最長邊最大值為max_size
- **conv5_3特征層大小:**通過查表法獲得縮放后圖像對應的conv5_3的大小(output_width_map,output_height_map)
- **網格化:**按照`feat_stride`將conv5_3的大小打成網格
- **所有anchors:**在網格每個節點上放入9個基本`anchors`,並獲得其坐標。
- **挑選樣本:**`proposal_prepare_image_roidb.m`文件中的`compute_targets`實現正例樣本和反例樣本的選取
- **計算overlap**:所有anchors存入變量`ex_rois`,計算每個anchor和每個groundtruth的重疊率(IoU)
- **去掉超出范圍的anchor**:將超出范圍的anchor和groundtruth的重疊率置0.
- **篩選正例樣本**:IoU最大的和IoU大於`fg_thresh`的anchor作為正例樣本
- **篩選反例樣本**:IoU介於`bg_thresh_hi`和`bg_thresh_lo`之間的作為反例樣本
- **計算回歸量**:通過文章中公式(2)計算每個正例樣本的回歸量`dx`,`dy`,`dw`,`dh`
- **新的groundtruth**:將正例樣本的回歸量作為正例樣本的groundtruth(類標1),反例樣本的回歸量均設為0(類標-1)。
- **計算均值方差**:計所有正例樣本的回歸量的均值和方差,並且標准化(減去均值,除以方差)
3 Training
,訓練
Step1: 打亂訓練數據順序 proposal_train.m
中的generate_random_minibatch
函數實現對訓練數據的打亂,並返回打亂后的第一幅圖像的標號sub_db_inds
。
Step2: 准備一個訓練數據 proposal_generate_minibatch.m
實現。
- 正反例樣本選取及權重設置:proposal_generate_minibatch.m
中的sample_rois
選取樣本並且設置權重
- fg_inds:正例樣本序號,如果不到batch_size
的fg_fraction
倍,則用反例樣本補足。
- bg_inds:反例樣本序號,反例樣本一般都比較多,需要進行隨機選取。
- label:對每個正例樣本label置1,反例樣本label置0.
- label_weights:樣本類別損失的權重。正例樣本置1,反例樣本置bg_weight
。
- bbox_targets:進行數據轉換后的正反例樣本窗口位置
- bbox_loss_weights:樣本位置損失的權重。正例為1,反例為0
- 整合RPN輸入blob
- **RPN輸入的im_blob:**im_blob
- **RPN輸入的labels_blob:**labels_blob
- **RPN輸入的label_weights_blob:**label_weights_blob
- **RPN輸入的bbox_targets_blob:**bbox_targets_blob
- **RPN輸入的bbox_loss_blob:**bbox_loss_blob
Step3: 迭代