非极大值抑制顾名思义就是抑制不是极大值的元素,搜索局部的极大值。这个局部代表的是一个邻域,邻域有两个参数可变,一个是邻域的维数,二是邻域的大小。这里不讨论通用的NMS算法,而是用于在目标检测中提取分数最高的窗口的。例如在行人检测中,滑动窗口经提取特征,经分类器分类识别后,每个窗口都会得到一个分数。但是滑动窗口会导致很多窗口与其他窗口存在包含或者大部分交叉的情况。这时就需要用到NMS来选取那些邻域里分数最高,并且抑制那些分数低的窗口。

# import the necessary packages
import numpy as np # Malisiewicz et al.
def non_max_suppression_fast(boxes, overlapThresh):
# if there are no boxes, return an empty list
if len(boxes) == 0:
return [] # if the bounding boxes integers, convert them to floats --
# this is important since we'll be doing a bunch of divisions
if boxes.dtype.kind == "i":
boxes = boxes.astype("float") # initialize the list of picked indexes
pick = [] # grab the coordinates of the bounding boxes
x1 = boxes[:,0]
y1 = boxes[:,1]
x2 = boxes[:,2]
y2 = boxes[:,3] # compute the area of the bounding boxes and sort the bounding
# boxes by the bottom-right y-coordinate of the bounding box
area = (x2 - x1 + 1) * (y2 - y1 + 1)
idxs = np.argsort(y2) # keep looping while some indexes still remain in the indexes
# list
while len(idxs) > 0:
# grab the last index in the indexes list and add the
# index value to the list of picked indexes
last = len(idxs) - 1
i = idxs[last]
pick.append(i) # find the largest (x, y) coordinates for the start of
# the bounding box and the smallest (x, y) coordinates
# for the end of the bounding box
xx1 = np.maximum(x1[i], x1[idxs[:last]])
yy1 = np.maximum(y1[i], y1[idxs[:last]])
xx2 = np.minimum(x2[i], x2[idxs[:last]])
yy2 = np.minimum(y2[i], y2[idxs[:last]]) # compute the width and height of the bounding box
w = np.maximum(0, xx2 - xx1 + 1)
h = np.maximum(0, yy2 - yy1 + 1) # compute the ratio of overlap
overlap = (w * h) / area[idxs[:last]] # delete all indexes from the index list that have
idxs = np.delete(idxs, np.concatenate(([last],
np.where(overlap > overlapThresh)[0]))) # return only the bounding boxes that were picked using the
# integer data type
return boxes[pick].astype("int")

非极大值抑制(NMS)的更多相关文章

  1. pytorch实现yolov3(4) 非极大值抑制nms

    在上一篇里我们实现了forward函数.得到了prediction.此时预测出了特别多的box以及各种class probability,现在我们要从中过滤出我们最终的预测box. 理解了yolov3 ...

  2. 非极大值抑制(Non-Maximum Suppression,NMS)

    概述 非极大值抑制(Non-Maximum Suppression,NMS),顾名思义就是抑制不是极大值的元素,可以理解为局部最大搜索.这个局部代表的是一个邻域,邻域有两个参数可变,一是邻域的维数,二 ...

  3. 目标检测 非极大值抑制(Non-Maximum Suppression,NMS)

    非极大值抑制(Non-Maximum Suppression,NMS),顾名思义就是抑制不是极大值的元素,可以理解为局部最大搜索.也可以理解为只取置信度最高的一个识别结果. 举例:  如图所示,现在 ...

  4. 非极大值抑制(NMS)

    转自:https://www.cnblogs.com/makefile/p/nms.html 概述 非极大值抑制(Non-Maximum Suppression,NMS),顾名思义就是抑制不是极大值的 ...

  5. 非极大值抑制(NMS)的几种实现

    因为之前对比了RoI pooling的几种实现,发现python.pytorch的自带工具函数速度确实很慢,所以这里再对Faster-RCNN中另一个速度瓶颈NMS做一个简单对比试验. 这里做了四组对 ...

  6. 非极大值抑制Non-Maximum Suppression(NMS)

    非极大值抑制(Non-Maximum Suppression,NMS)   概述 非极大值抑制(Non-Maximum Suppression,NMS),顾名思义就是抑制不是极大值的元素,可以理解为局 ...

  7. 输出预测边界框,NMS非极大值抑制

    我们预测阶段时: 生成多个锚框 每个锚框预测类别和偏移量 但是,当同一个目标上可能输出较多的相似的预测边界框.我们可以移除相似的预测边界框.——NMS(非极大值抑制). 对于一个预测边界框B,模型会计 ...

  8. IoU与非极大值抑制(NMS)的理解与实现

    1. IoU(区域交并比) 计算IoU的公式如下图,可以看到IoU是一个比值,即交并比. 在分子中,我们计算预测框和ground-truth之间的重叠区域: 分母是并集区域,或者更简单地说,是预测框和 ...

  9. NMS(Non-Maximum Suppression) 非极大值抑制

    NMS  非极大值抑制:找到局部最大值,并删除邻域内其他的值. 简单说一下流程: 首先剔除背景(背景无需NMS),假设有6个边界框,根据分类置信度对这6个边界框做降序排列,假设顺序为A.B.C.D.E ...

随机推荐

  1. jinja2主要语法

    jinja2主要语法 1.变量 {{name}} 2.控制语句 {% if %} {{name}} {% else %} {{name2}} {% endif%} 3.宏 {% macro check ...

  2. pyinstaller 将.py生成.exe ----报错 “IndexError: tuple index out of range”

    pyinstaller将py打包为exe文件,用pysintaller居然报错 File "c:\anaconda3\lib\site-packages\PyInstaller\depend ...

  3. WebForm的初步认识

    嘿嘿,这里就简单的总结一下初步学习webform以及对他的认识,其实大家都认为webform很讨厌,因为好多都是给我们封装好的,而且现在好多的公司已经慢慢的从中逃离出来选择使用mvc架构,甚至好多的项 ...

  4. 在linux下搭建ftp服务器【转】

    1 安装 vsftpd yum install vsftpd 2 配置 vsftpd 打开 vsftpd 文件: vi /etc/vsftpd/vsftpd.conf 初次修改前建议备份该文件 2.1 ...

  5. Java中遍历字符串toCharArray()和charAt()效率比较

    public static void test() { String s = "a"; for(int i = 0; i < 100000; i++) { s += &quo ...

  6. JavaScript中Array

    一,针对于数组 const arr = ['a','b','c','d']; Array.indexOf  将“返回第一次出现给定元素的索引”; console.log(arr.indexOf('b' ...

  7. Robotium源码解读-native控件/webview元素的获取和操作

    目前比较有名的Uitest框架有Uiautomator/Robotium/Appium,由于一直对webview元素的获取和操作比较好奇,另外Robotium代码量也不是很大,因此打算学习一下. 一. ...

  8. IIS "rewrite.dll failed to load. The data is the error." 错误解决方法

    在Windows 10 build 17133.73上部署一个较老版本的ASP.NET 2.0程序,访问时候出现: Service Unavailable HTTP Error 503. The se ...

  9. 状态机FSM

    参考: 百度-有限状态机 博客园-有限状态机FSM详解及其实现 CSDN-状态机FSM代码框架 腾讯开源项目behaviac 占坑,待编辑...

  10. IOS开发 REST请求 ASIHTTPRequest用法

    ASIHTTPRequest类库简介和使用说明 官方网站: http://allseeing-i.com/ASIHTTPRequest/ .可以从上面下载到最新源码,以及获取到相关的资料. 使用iOS ...