zoukankan      html  css  js  c++  java
  • 非极大值抑制(non-maximum suppression)的理解与实现

    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;
    end
    
    x1 = 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);
    end
    
    end
  • 相关阅读:
    ibatis实战之一对多关联
    ibatis实战之OR映射
    ibatis配置log4j输出sql日志信息
    MyEclipse添加ibatis DTD文件实现xml的自动提示功能
    ibatis实战之基础环境搭建
    ORA-12520错误解决方法
    springMVC3学习(十二)--文件上传优化CommonsMultipartResolver
    转:sql语句优化
    转:Sql Server中的表访问方式Table Scan, Index Scan, Index Seek
    SQL Server优化
  • 原文地址:https://www.cnblogs.com/mtcnn/p/9421527.html
Copyright © 2011-2022 走看看