非极大抑制(Non-maximum suppression)python代码实现
原创Butertfly 发布于2018-11-20 18:48:57 阅读数 293 收藏
展开
定位一个物体,最后算法就找出了一堆的方框,我们需要判别哪些矩形框是没用的。非极大值抑制:先假设有6个矩形框,根据分类器类别分类概率做排序,从大到小分别属于物体的概率分别为A、B、C、D、E、F。

(1)从最大概率矩形框F开始,分别判断B~F与A的重叠度IOU是否大于某个设定的阈值;

(2)假设B、D与F的重叠度超过阈值,那么就扔掉B、D;并标记第一个矩形框A,是我们保留下来的。

(3)从剩下的矩形框C、E、F中,选择概率最大的C,然后判断C与E、F的重叠度,重叠度大于一定的阈值,那么就扔掉;并标记C是我们保留下来的第二个矩形框。

就这样一直重复,找到所有被保留下来的矩形框。

# import the necessary packages
import numpy as np

# Felzenszwalb et al.
def non_max_suppression_slow(boxes, thresh):
# if there are no boxes, return an empty list
if len(boxes) == 0:
return []

# 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]
scores = boxes[:, 4]

# 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)

# 获取置信度,并降序排列,获取其在boxes中对应的索引
idxs = scores.argsort()[::-1]

while idxs.size > 0:
i = idxs[0]
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[1:]])
yy1 = np.maximum(y1[i], y1[idxs[1:]])
xx2 = np.minimum(x2[i], x2[idxs[1:]])
yy2 = np.minimum(y2[i], y2[idxs[1:]])

# compute the width and height of the bounding box
w = np.maximum(0.0, xx2 - xx1 + 1)
h = np.maximum(0.0, yy2 - yy1 + 1)

# compute the intersection over union(IOU) between the computed
# bounding box and the bounding box in the area list
inter = w * h
union = area[i] + area[idxs[1:]] - inter
IOU = inter / union

indexes = np.where(IOU < thresh)

idxs = idxs[indexes + 1]

# return only the bounding boxes that were picked
return boxes[pick]

References:

1.https://www.pyimagesearch.com/2014/11/17/non-maximum-suppression-object-detection-python/

2.https://blog.csdn.net/l_ml_m_lm_m/article/details/79881437

3.https://blog.csdn.net/u011534057/article/details/51235718

4.http://www.cnblogs.com/makefile/p/nms.html

————————————————
版权声明:本文为CSDN博主「Butertfly」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/Butertfly/article/details/84307659

非极大抑制睔PYTHON实现的更多相关文章

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

    非极大抑制(Non-Maximum Suppression) Non-Maximum Suppression for Object Detection in Python RCNN 和微软提出的 SP ...

  2. 第二十七节,IOU和非极大值抑制

    你如何判断对象检测算法运作良好呢?在这一节中,你将了解到并交比函数,可以用来评价对象检测算法. 一 并交比(Intersection over union ) 在对象检测任务中,你希望能够同时定位对象 ...

  3. 【56】目标检测之NMS非极大值抑制

    非极大值抑制(Non-max suppression) 到目前为止你们学到的对象检测中的一个问题是,你的算法可能对同一个对象做出多次检测,所以算法不是对某个对象检测出一次,而是检测出多次.非极大值抑制 ...

  4. 『Python』图像金字塔、滑动窗口和非极大值抑制实现

    图像金字塔 1.在从cv2.resize中,传入参数时先列后行的 2.使用了python中的生成器,调用时使用for i in pyramid即可 3.scaleFactor是缩放因子,需要保证缩放后 ...

  5. 非极大值抑制算法(Python实现)

    date: 2017-07-21 16:48:02 非极大值抑制算法(Non-maximum suppression, NMS) 算法原理 非极大值抑制算法的本质是搜索局部极大值,抑制非极大值元素. ...

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

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

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

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

  8. 非极大值抑制(NMS)

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

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

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

随机推荐

  1. PB开启源码文件

    下载的源码没有pbw文件,新建workspace,然后new Target选existing application

  2. 验证码校验(Ajax)

    show.jsp <%@ page language="java" contentType="text/html; charset=utf-8" page ...

  3. 「国家集训队」middle

    「国家集训队」middle 传送门 按照中位数题的套路,二分答案 \(mid\),序列中 \(\ge mid\) 记为 \(1\),\(< mid\) 的记为 \(-1\) 然后只要存在一个区间 ...

  4. javascript对象创建及继承

    //****************************************************************************** //创建类的多种方式 //------ ...

  5. golang的io.copy使用

    net/http 下载 在golang中,如果我们要下载一个文件,最简单的就是先用http.get()方法创建一个远程的请求后,后面可使用ioutil.WriteFile()等将请求内容直接写到文件中 ...

  6. python时间序列按频率生成日期的方法

    引用:https://www.zhangshengrong.com/p/281omE7rNw/ 有时候我们的数据是按某个频率收集的,比如每日.每月.每15分钟,那么我们怎么产生对应频率的索引呢?pan ...

  7. 第五周之Hadoop学习(五)

    在上周已经完成Hadoop的Java编程环境下的配置,这周则是通过对Eclipse的环境编程对Hadoop的API进行简单的调用 参考地址:https://blog.csdn.net/u0105237 ...

  8. 【原】php中fastcgi和php-fpm是什么东西

    fastcgi 是一个与平台无关,与语言无关,任何语言只要按照它的接口来实现,就能实现自己语言的fastcgi能力和web server 通讯. PHP-CGI就是PHP实现的自带的FastCGI管理 ...

  9. Java基础 -4.3

    While循环结构 while循环 public static void main(String[] args) { while(布尔表达式) { 条件满足时执行; 修改循环条件; } } do wh ...

  10. IELTS Simon wr task p3