解析网络结构 http://blog.youkuaiyun.com/sloanqin/article/details/51545125
anchor 产生 http://blog.youkuaiyun.com/xzzppp/article/details/52317863
http://blog.youkuaiyun.com/u012905422/article/details/52634208
部分代码解析
http://www.cnblogs.com/573177885qq/p/6141507.html
im = single(im);
[im_blob, im_scales] = get_image_blob(conf, im);
im_size = size(im);
scaled_im_size = round(im_size * im_scales);
% permute data into caffe c++ memory, thus [num, channels, height, width]
im_blob = im_blob(:, :, [3, 2, 1], :); % from rgb to brg
im_blob = permute(im_blob, [2, 1, 3, 4]);
im_blob = single(im_blob);
net_inputs = {im_blob};
% Reshape net's input blobs
caffe_net.reshape_as_input(net_inputs);
output_blobs = caffe_net.forward(net_inputs);%得到cls layer 和 reg layer的输出结果
% Apply bounding-box regression deltas
box_deltas = output_blobs{1};%位置回归参数
featuremap_size = [size(box_deltas, 2), size(box_deltas, 1)];
% permute from [width, height, channel] to [channel, height, width], where channel is the
% fastest dimension
box_deltas = permute(box_deltas, [3, 2, 1]);
box_deltas = reshape(box_deltas, 4, [])';
anchors = proposal_locate_anchors(conf, size(im), conf.test_scales, featuremap_size);%产生所有的anchor 15*15*9
pred_boxes = fast_rcnn_bbox_transform_inv(anchors, box_deltas);%变回gt
% scale back
pred_boxes = bsxfun(@times, pred_boxes - 1, ...
([im_size(2), im_size(1), im_size(2), im_size(1)] - 1) ./ ([scaled_im_size(2), scaled_im_size(1), scaled_im_size(2), scaled_im_size(1)] - 1)) + 1;%映射会原图位置
pred_boxes = clip_boxes(pred_boxes, size(im, 2), size(im, 1));
assert(conf.test_binary == false);
% use softmax estimated probabilities
scores = output_blobs{2}(:, :, end);%得到分数背景或对象
scores = reshape(scores, size(output_blobs{1}, 1), size(output_blobs{1}, 2), []);
% permute from [width, height, channel] to [channel, height, width], where channel is the
% fastest dimension
scores = permute(scores, [3, 2, 1]);
scores = scores(:);
box_deltas_ = box_deltas;
anchors_ = anchors;
scores_ = scores;
if conf.test_drop_boxes_runoff_image
contained_in_image = is_contain_in_image(anchors, round(size(im) * im_scales));
pred_boxes = pred_boxes(contained_in_image, :);
scores = scores(contained_in_image, :);
end
% drop too small boxes
[pred_boxes, scores] = filter_boxes(conf.test_min_box_size, conf.test_min_box_height, pred_boxes, scores);
% sort
[scores, scores_ind] = sort(scores, 'descend');
pred_boxes = pred_boxes(scores_ind, :);