当前位置:网站首页>Recorded target detection NMS (non maximum suppression)
Recorded target detection NMS (non maximum suppression)
2022-07-26 02:21:00 【NuerNuer】
NMS thought :
1. First, sort all boxes by confidence , Select the box with the highest confidence , Write it down as S
2. Remaining boxes and S do IOU Calculation , Greater than the set threshold threshold ( permanent 0.7) Others are suppressed , The most basic suppression method is to set the confidence of these boxes 0.
3. Continue to find the one with the highest score in the remaining boxes , repeat 1,2. To the box without repetition , Algorithm stop .
pytorch Realization ( quote :https://blog.csdn.net/KANG157/article/details/124649838):
For specific analysis, I gave comments in the code
def NMS(boxes,scores, thresholds):
x1 = boxes[:,0] # Top left x
y1 = boxes[:,1] # Top left y
x2 = boxes[:,2] # Lower right x
y2 = boxes[:,3] # Lower right y
areas = (x2-x1)*(y2-y1) # Calculate the area of each box , There is aeras in
_,order = scores.sort(0,descending=True) # Rank the scores of all boxes in descending order , return order Indexes
keep = []
while order.numel() > 0: # When order The number of elements is not 0
i = order[0] # Get the index with the highest score and assign it to i, Remember this box as S
keep.append(i) # Add in keep Set
if order.numel() == 1: # If there is only one box , Then the algorithm ends
break
xx1 = x1[order[1:]].clamp(min=x1[i]) # adopt clamp function , Check the remaining boxes and S The upper left point of the intersection x value
yy1 = y1[order[1:]].clamp(min=y1[i]) # adopt clamp function , Check the remaining boxes and S The upper left point of the intersection y value
xx2 = x2[order[1:]].clamp(max=x2[i]) # adopt clamp function , Check the remaining boxes and S The lower right point of the intersection x value
yy2 = y2[order[1:]].clamp(max=y2[i]) # adopt clamp function , Check the remaining boxes and S The upper left point of the intersection x value
w = (xx2-xx1).clamp(min=0) # Will intersect width Negative values are limited to 0, The goal is a box without intersection , The intersection part is set to 0
h = (yy2-yy1).clamp(min=0) # Will intersect height Negative values are limited to 0, ditto
inter = w*h # Calculate the intersection area
ovr = inter/(areas[i] + areas[order[1:]] - inter) # Calculation iou
ids = (ovr<=thresholds).nonzero().squeeze() # Get all iou The index of the box whose value is less than the threshold
if ids.numel() == 0: # When does not exist and the current box iou When the value is less than the threshold box , Code end
break
order = order[ids+1] # Pay attention to the addition here 1, because ids The calculation is in addition to the first box , Make a recovery to order Step back 1 individual , So add 1
return torch.LongTensor(keep)Function analysis :
torch.sort(input, dim=0, descending=False)
dim: Sort dimension
descending: Descending or not
return:1. An ordered array
2. The corresponding index torch.clamp(input, min=a, max=b)
usage: take input Data is limited to [a,b] In closed interval
principle :
input[i] = a, if input[i] <= a
= input[i] if input[i] > a and input[i] < b
= b if input[i] >= btorch.nonzero(input)
return: input Central Africa 0 Index of elements 边栏推荐
猜你喜欢

Error reporting caused by local warehouse

【云原生】4.1 DevOps基础与实战

Ti AM335X工控模块使用beaglebone(bbb)的Debian系统

Acwing 379. hide and seek problem solution (minimum path non repeating point coverage)

增删改查业务的快速上手

I.MX6UL核心模块使用连载-nand flash读写测试 (三)

微信小程序解密并拆包获取源码教程

Wechat applet decryption and unpacking to obtain source code tutorial

2. Login - verification code function and saving login status

1. Mx6ul core module serial Ethernet test (VII)
随机推荐
[C]详解语言文件操作
Navica tool imports remote MySQL into local MySQL database
Niuke net question brushing training (I)
IDEA运行web项目出现乱码问题有效解决(附详细步骤)
Acwing 379. hide and seek problem solution (minimum path non repeating point coverage)
ERROR: could not extract tar starting at offset 000000000000020980+9231072+2
[xxl-job] xxl-job learning
What is JSX?
LeetCode_ Dynamic programming_ Medium_ 264. Ugly number II
I came to the library applet check-in process analysis
Adruino basic experimental learning (I)
I.MX6UL核心模块使用连载-WIFI测试 (八)
项目管理:精益管理法
BigDecimal use
[red team] att & CK - using bits services to achieve persistence
MySQL transaction isolation level
A MCU event driven C framework
Quick start of adding, deleting, modifying and checking business
国标GB28181协议视频平台EasyGBS消息弹框模式优化
U++ common type conversion and common forms and proxies of lambda