非极大值抑制(non-maximum suppression)的理解与实现

分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.youkuaiyun.com/jiangjunshow

也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!

                       

RCNN 和微软提出的 SPP_net 等著名的目标检测模型,在算法具体的实施过程中,一般都会用到 non-maximum suppress(非最大值抑制,抑制即忽略, 也即忽略那些(IoU)高于提供的阈值的) 的机制。

引入 non-maximum suppression 的目的在于:根据事先提供的 score 向量,以及 regions(由不同的 bounding boxes,矩形窗口左上和右下点的坐标构成) 的坐标信息,从中筛选出置信度较高的 bounding boxes。

其基本操作流程如下:

  • 首先,计算每一个 bounding box 的面积:
    • (x1, y1) ⇒ 左上点的坐标,(x2, y2) ⇒ 右下点的坐标;
    • (x2-x1+1)x(y2-y1+1)
  • 根据 scores 进行排序(一般从小到大),将 score 最大的bounding box置于队列,接下来计算其余 bounding box 与当前 score 最大的 bounding box 的 IoU,抑制(忽略也即去除)IoU大于设定阈值的 bounding box;
  • 重复以上过程,直至候选 bounding boxes 为空;
function picked = nms(boxes, overlap_thresh)% boxes[:, 1:4] 存储着 regions 信息,boxes[:, 5] 存储的则是 scores 向量if isempty(boxes)    picked = [];    return;endx1 = boxes[:, 1];y1 = boxes[:, 2];           % (x1, y1) ⇒ bounding boxes 左上点坐标的集合x2 = boxes[:, 3];y2 = boxes[:, 4];           % (x2, y2) ⇒ bounding boxes 右下点坐标的集合s = boxes[:, 5];            % scores 向量areas = (x2-x1+1).*(y2-y1+1);   % 各个 bounding boxes 的面积[vals, idx] = sort(s);      % 默认从小到大排序while ~isempty(idx)    last = length(idx);    i = idx(last);    picked = [picked, i];    xx1 = max(x1(i), x1(1:last-1));    yy1 = max(y1(i), y1(1:last-1));    xx2 = min(x2(i), x2(1:last-1));    yy2 = min(y2(i), y2(1:last-1));    h = max(0, yy2-yy1+1);    w = max(0, xx2-xx1+1);    inter = w .* h;    iou = inter ./ (areas(i) + areas(1:last-1)-inter);    I = I(iou <= overlap_thresh);endend
  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
           

给我老师的人工智能教程打call!http://blog.youkuaiyun.com/jiangjunshow
这里写图片描述
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值