非极大抑制睔PYTHON实现
非极大抑制(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实现的更多相关文章
- 非极大值抑制(non-maximum suppression)的理解与实现
非极大抑制(Non-Maximum Suppression) Non-Maximum Suppression for Object Detection in Python RCNN 和微软提出的 SP ...
- 第二十七节,IOU和非极大值抑制
你如何判断对象检测算法运作良好呢?在这一节中,你将了解到并交比函数,可以用来评价对象检测算法. 一 并交比(Intersection over union ) 在对象检测任务中,你希望能够同时定位对象 ...
- 【56】目标检测之NMS非极大值抑制
非极大值抑制(Non-max suppression) 到目前为止你们学到的对象检测中的一个问题是,你的算法可能对同一个对象做出多次检测,所以算法不是对某个对象检测出一次,而是检测出多次.非极大值抑制 ...
- 『Python』图像金字塔、滑动窗口和非极大值抑制实现
图像金字塔 1.在从cv2.resize中,传入参数时先列后行的 2.使用了python中的生成器,调用时使用for i in pyramid即可 3.scaleFactor是缩放因子,需要保证缩放后 ...
- 非极大值抑制算法(Python实现)
date: 2017-07-21 16:48:02 非极大值抑制算法(Non-maximum suppression, NMS) 算法原理 非极大值抑制算法的本质是搜索局部极大值,抑制非极大值元素. ...
- 非极大值抑制(NMS)的几种实现
因为之前对比了RoI pooling的几种实现,发现python.pytorch的自带工具函数速度确实很慢,所以这里再对Faster-RCNN中另一个速度瓶颈NMS做一个简单对比试验. 这里做了四组对 ...
- 非极大值抑制(Non-Maximum Suppression,NMS)
概述 非极大值抑制(Non-Maximum Suppression,NMS),顾名思义就是抑制不是极大值的元素,可以理解为局部最大搜索.这个局部代表的是一个邻域,邻域有两个参数可变,一是邻域的维数,二 ...
- 非极大值抑制(NMS)
转自:https://www.cnblogs.com/makefile/p/nms.html 概述 非极大值抑制(Non-Maximum Suppression,NMS),顾名思义就是抑制不是极大值的 ...
- 非极大值抑制Non-Maximum Suppression(NMS)
非极大值抑制(Non-Maximum Suppression,NMS) 概述 非极大值抑制(Non-Maximum Suppression,NMS),顾名思义就是抑制不是极大值的元素,可以理解为局 ...
随机推荐
- state thread api 查询
state thread api 查询: http://state-threads.sourceforge.net/docs/reference.html
- redis requires Ruby version >= 2.2.2 系统默认 ruby 版本过低,导致 Redis 接口安装失败
安装 Redis 接口时异常 ,系统 ruby 版本过低 ! 输入命令 " gem install redis " 出现 " ERROR: Error installi ...
- HashMap中推荐使用entrySet方式遍历Map类集合KV而不是keySet方式遍历
我们先来做一个测试 public class HashMapTest { private HashMap<String, String> map = new HashMap<> ...
- 穿越雷区--蓝桥杯--DFS/BFS
题目描述 X星的坦克战车很奇怪,它必须交替地穿越正能量辐射区和负能量辐射区才能保持正常运转,否则将报废. 某坦克需要从A区到B区去(A,B区本身是安全区,没有正能量或负能量特征),怎样走才能路径最短? ...
- 计算xx年xx月xx日是星期几
代码: #include <iostream> #include <string> #include <vector> using namespace std; i ...
- 32 commons-lang包学习
maven依赖 <dependency> <groupId>commons-lang</groupId> <artifactId>commons-lan ...
- redhat 7.6 网络配置
网卡配置目录 /etc/sysconfig/network-scripts/ 关闭网卡 $$ 打开网卡 ifdown ensp8 && ifup ensp8 重启网卡服务 servic ...
- List模拟栈
import java.util.LinkedList; import java.util.List; import java.util.Scanner; public class Main<E ...
- 查漏补缺之go依赖管理
vendor 使用vendor进行包管理,首先要保证项目在$GOPATH/src/路径下(踩过坑),然后build时就会按照如图所示的优先级进行包的搜索. 一个没有找到包的实例: module 其他 ...
- springMVC的执行请求过程
springMVC的运行流程: 1.用户发送请求至前端控制器DispatcherServlet 2.DispatcherServlet收到请求调用HandlerMapping处理器映射器 3.处理器映 ...