非极大抑制睔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),顾名思义就是抑制不是极大值的元素,可以理解为局 ...
随机推荐
- The Last Puzzle ZOJ - 3541
题目链接 本题也是区间dp,贪心可证,每一次出发必定是从端点,否则必然有重复,不会是最小值,那我们可以设dpi,j,0/1,0代表从左端点出发,1代表从右端点,因为每次都是从端点出发,状态方程为 dp ...
- kafka2x-Elasticsearch 数据同步工具demo
Bboss is a good elasticsearch Java rest client. It operates and accesses elasticsearch in a way simi ...
- 解决idea创建maven项目无java
在idea上创建maven-archetype-webapp项目后发现无法创建java文件然后参考此博客得以解决 https://www.cnblogs.com/mywangpingan/p/9448 ...
- 吴裕雄--天生自然ORACLE数据库学习笔记:过程、函数、触发器和包
create procedure pro_insertDept is begin ,'市场拓展部','JILIN'); --插入数据记录 commit; --提交数据 dbms_output.put_ ...
- 吴裕雄 Bootstrap 前端框架开发——Bootstrap 排版:标题
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- redis小功能大用处-bitmaps
- vector的clear和swap
vector的clear()操作只是清空vector的元素,而不会将内存释放掉 vector<int> vec1{ 1,2,3,4,5 }; vec1.clear(); cout<& ...
- html-webpack-plugin & clean-webpack-plugin
html-webpack-plugin Introduction: The HtmlWebpackPlugin simplifies creation of HTML files to serve y ...
- Xftp和Xshell
Xftp 用于跟云虚拟机文件传输的工具,Xftp官网 Xshell Xftp的兄弟工具,用于执行云虚拟机命令,Xshell官网 两个都是付费工具,各需要几百块钱,当然破解的版本也很多 登陆 这两个的连 ...
- 「JSOI2010」满汉全席
前言 由于蒟蒻才刚开始学 \(\text{2-SAT}\),所以题解中有的地方可能不够精炼,望多包涵! 题目描述 题目意思很简单,标准的\(\text{2-SAT}\)问题模型.那么我们就先来介绍一下 ...