【NMS】nms_multiclass.m

在Faster RCNN中常见的NMS是在rpn的最后一步,合并重复的IOU用的,由于RPN的预测只有前景和背景之分,所以目前我看到的代码中所用的NMS都是不是多类别的NMS,但是在YOLO这种网络中应该需要用到多类别的NMS。

function picks = nms_multiclass(boxes, overlap)

%%boxes为一个m*n的矩阵,其中m为boundingbox的个数,n的前4列为每个boundingbox的坐标,格式为
%%(x1,y1,x2,y2);第5:n列为每一类的置信度,一共n-5+1个置信度

% top = nms(boxes, overlap)
% Non-maximum suppression. (FAST VERSION)
% Greedily select high-scoring detections and skip detections
% that are significantly covered by a previously selected
% detection.
%
% NOTE: This is adapted from Pedro Felzenszwalb's version (nms.m),
% but an inner loop has been eliminated to significantly speed it
% up in the case of a large number of boxes

% Copyright (C) 2011-12 by Tomasz Malisiewicz
% All rights reserved.
% 
% This file is part of the Exemplar-SVM library and is made
% available under the terms of the MIT license (see COPYING file).
% Project homepage: https://github.com/quantombone/exemplarsvm


if isempty(boxes)
  picks = {};
  return;
end

if size(boxes, 1) < 10000
    picks = nms_multiclass_mex(double(boxes), double(overlap));
    return;
end

x1 = boxes(:,1);
y1 = boxes(:,2);
x2 = boxes(:,3);
y2 = boxes(:,4);

area = (x2-x1+1) .* (y2-y1+1);

picks = cell(size(boxes, 2)-4, 1);
%在不同类别内分别做NMS
for iS = 5:size(boxes, 2)
    s = boxes(:,iS);
    [~, I] = sort(s);

    pick = s*0;
    counter = 1;
    while ~isempty(I)
      last = length(I);
      i = I(last);  
      pick(counter) = i;
      counter = counter + 1;

      xx1 = max(x1(i), x1(I(1:last-1)));
      yy1 = max(y1(i), y1(I(1:last-1)));
      xx2 = min(x2(i), x2(I(1:last-1)));
      yy2 = min(y2(i), y2(I(1:last-1)));

      w = max(0.0, xx2-xx1+1);
      h = max(0.0, yy2-yy1+1);

      inter = w.*h;
      o = inter ./ (area(i) + area(I(1:last-1)) - inter);

      I = I(o<=overlap);
    end

    pick = pick(1:(counter-1));
    picks{iS-4} = pick;
end

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值