Faster RCNN 源码解读(2) -- NMS(非极大抑制)
来源:互联网 发布:海森伯格矩阵是什么 编辑:程序博客网 时间:2024/06/05 05:46
NMS简介
非极大抑制算法应用相当广泛,其主要目的是消除多余的框,找到最佳的物体检测位置。
其实现的思想主要是将各个框的置信度进行排序,然后选择其中置信度最高的框A,将其作为标准选择其他框,同时设置一个阈值,当其他框B与A的重合程度超过阈值就将B舍弃掉,然后在剩余的框中选择置信度最大的框,重复上述操作。
定义dets矩阵与阈值
import numpy as npdets = np.array([ [204, 102, 358, 250, 0.5], [257, 118, 380, 250, 0.7], [280, 135, 400, 250, 0.6], [255, 118, 360, 235, 0.7]])thresh = 0.3
其中,二维数组dets的每一维分别表示为xmin, ymin, xmax, ymax, confidence。
lib/nms/py_cpu_nms.py
对于Python代码而言,NMS实现的核心是在lib/nms/py_cpu_nms.py的代码。因此接下来就其细节进行详尽的分析:
import numpy as npdef py_cpu_nms(dets, thresh): """Pure Python NMS baseline.""" x1 = dets[:, 0] #xmin y1 = dets[:, 1] #ymin x2 = dets[:, 2] #xmax y2 = dets[:, 3] #ymax scores = dets[:, 4] #confidence areas = (x2 - x1 + 1) * (y2 - y1 + 1) #the size of bbox order = scores.argsort()[::-1] #sort bounding boxes by decreasing order, returning array([3, 1, 2, 0]) keep = [] # store the final bounding boxes while order.size > 0: i = order[0] #the index of the bbox with highest confidence keep.append(i) #save it to keep xx1 = np.maximum(x1[i], x1[order[1:]]) #array([ 257., 280., 255.]) yy1 = np.maximum(y1[i], y1[order[1:]]) #array([ 118., 135., 118.]) xx2 = np.minimum(x2[i], x2[order[1:]]) #array([ 360., 360., 358.]) yy2 = np.minimum(y2[i], y2[order[1:]]) #array([ 235., 235., 235.]) w = np.maximum(0.0, xx2 - xx1 + 1) #array([ 104., 81., 104.]) h = np.maximum(0.0, yy2 - yy1 + 1) #array([ 118., 101., 118.]) inter = w * h #array([ 12272., 8181., 12272.]) # Cross Area / (bbox + particular area - Cross Area) ovr = inter / (areas[i] + areas[order[1:]] - inter) #reserve all the boundingbox whose ovr less than thresh inds = np.where(ovr <= thresh)[0] order = order[inds + 1] return keep
参考资料
Faster RCNN – NMS
NMS解析
阅读全文
0 0
- Faster RCNN 源码解读(2) -- NMS(非极大抑制)
- NMS-----非极大抑制
- faster rcnn源码解读2
- faster rcnn 源码解读
- faster rcnn 源码解读
- 深度学习——NMS(非极大抑制)
- faster rcnn源码解读总结
- faster rcnn源码解读总结
- faster rcnn 源码解读1
- NMS非极大值抑制
- 非极大值抑制 NMS
- 非极大值抑制NMS
- 非极大值抑制(NMS)
- 非最大抑制(NMS)
- 非最大抑制(NMS)
- 非极大值抑制(NMS)
- NMS(非极大值抑制)
- 非最大抑制(NMS)
- 【Unity3d游戏开发】浅谈Unity中的GC以及优化(转)
- 服务器上是部署JDK 、还是JRE
- 删除JSONArray中的某个元素
- 数字货币虚拟币点对点模式系统平台搭建,场外交易模式系统定制开发
- 知道这20个正则表达式,能让你少写1,000行代码
- Faster RCNN 源码解读(2) -- NMS(非极大抑制)
- 文章标题
- [自制操作系统] BMP格式文件读取&图形界面系统框架-应用接口设计
- leetcode 552. Student Attendance Record II & 600. Non-negative Integers without Consecutive Ones
- 纯JAVA HTTPURL 访问制定url地址返回页面数据
- Contest1255
- 原生链
- (算法分析Week2)3Sum[Medium]
- python类继承需要注意的问题