当前位置:网站首页>Face warp - hand tear code
Face warp - hand tear code
2022-07-28 09:18:00 【dadaHaHa1234】
IoU
Rectangular box IoU
def compute_iou(rec1, rec2):
"""
computing IoU
param rec1: (y0, x0, y1, x1) , which reflects (top, left, bottom, right)
param rec2: (y0, x0, y1, x1) , which reflects (top, left, bottom, right)
return : scale value of IoU
"""
S_rec1 =(rec1[2] -rec1[0]) *(rec1[3] -rec1[1])
S_rec2 =(rec2[2] -rec2[0]) *(rec2[3] -rec2[1])
#computing the sum area
sum_area =S_rec1 +S_rec2
#find the each edge of interest rectangle
in_h = min(rec1[2], rec2[2]) - max(rec1[0], rec2[0])
in_w = min(rec1[3], rec2[3]) - max(rec1[1], rec2[1])
#judge if interact
inter = 0 if in_h<0 or in_w<0 else in_h*in_w
return intersect /(sum_area -intersect)
Rotate the target IoU
from shapely.geometry import Polygon
def intersection(g, p):
g=np.asarray(g)
p=np.asarray(p)
g = Polygon(g[:8].reshape((4, 2)))
p = Polygon(p[:8].reshape((4, 2)))
if not g.is_valid or not p.is_valid:
return 0
inter = Polygon(g).intersection(Polygon(p)).area
union = g.area + p.area - inter
if union == 0:
return 0
else:
return inter/union
Semantically segmented IoU
NMS
Rectangle box NMS
def nms_cpu(dets, thresh):
dets = dets.numpy()
x1 = dets[:, 0] # Take out the top left corner of all the bounding boxes x Put the coordinates in x1
y1 = dets[:, 1]
x2 = dets[:, 2]
y2 = dets[:, 3]
scores = dets[:, 4]
areas = (x2 - x1 + 1) * (y2 - y1 + 1) # Calculate the area of all bounding boxes
# numpy Of argsort() function : Returns the index value of the array value from small to large ,
# Plus [::-1] Return the index value of the array value from large to small ,
# It's fine too order = np.argsort(-score)
order = scores.argsort()[::-1] # The index value of the score from large to small
# Every time you choose scores The largest bounding box in
keep = []
while order.size > 0:
i = order[0]
keep.append(i) # Keep the rest of this class box The index with the highest score in
xx1 = np.maximum(x1[i], x1[order[1:]])# Get the top left corner of the overlapping area between the bounding box with the highest score and all other boxes x coordinate
yy1 = np.maximum(y1[i], y1[order[1:]])# Scalar sum numpy Take the maximum value , The result is a numpy
xx2 = np.minimum(x2[i], x2[order[1:]])# Here is minimun, No maximum. Find the lower right corner of the overlapping area between the bounding box with the highest score and all other boxes x coordinate
yy2 = np.minimum(y2[i], y2[order[1:]])
# Calculate the area of overlap , The area without overlapping is 0
w = np.maximum(0.0, xx2 - xx1 + 1)
h = np.maximum(0.0, yy2 - yy1 + 1)
inter = w * h# Get the overlapping area of the maximum score box and other boxes
# Calculation IOU= Overlap area /( The area of the box with the largest score + Current frame area - Overlap area )
ovr = inter / (areas[i] + areas[order[1:]] - inter)
# Retain iou Bounding box less than or equal to the threshold , Others are filtered
# numpy.where() There are two uses :
# 1.np.where(condition, x, y): Meet the conditions (condition), Output x, Not satisfied with output y.
# 2.np.where(condition): The output condition is satisfied ( It's not 0) The coordinates of the elements ( Equivalent to numpy.nonzero)
inds = np.where(ovr <= thresh)[0]# Small overlapping area means to keep
# because ovr The length of the array is larger than order The array is one less , So here we need to move all subscripts back one bit ,
# Get the index of the next target area with the highest score
order = order[inds + 1]
return torch.IntTensor(keep)
soft_NMS
def soft_nms(boxes, sigma=0.5, threshold1=0.7, threshold2=0.1, method=1):
'''
paper:Improving Object Detection With One Line of Code
'''
N = boxes.shape[0]
pos = 0
maxscore = 0
maxpos = 0
for i in range(N):
# Find the prediction box with the highest score by bubble sorting , And put the prediction box on the i A place
maxscore = boxes[i, 4]
maxpos = i
# First, use some intermediate variables to store the i A prediction box
tx1 = boxes[i, 0]
ty1 = boxes[i, 1]
tx2 = boxes[i, 2]
ty2 = boxes[i, 3]
ts = boxes[i, 4]
pos = i + 1
# Get the highest score box
while pos < N:
if maxscore < boxes[pos, 4]:
maxscore = boxes[pos, 4]
maxpos = pos
pos = pos + 1
# In exchange for i individual box And the one with the highest score box, Will score the highest box Put it in the i A place
boxes[i, 0] = boxes[maxpos, 0]
boxes[i, 1] = boxes[maxpos, 1]
boxes[i, 2] = boxes[maxpos, 2]
boxes[i, 3] = boxes[maxpos, 3]
boxes[i, 4] = boxes[maxpos, 4]
# Put the original article i A prediction box is placed at the highest score
boxes[maxpos, 0] = tx1
boxes[maxpos, 1] = ty1
boxes[maxpos, 2] = tx2
boxes[maxpos, 3] = ty2
boxes[maxpos, 4] = ts
# The program is now realized : Search for the first i To N The box with the highest score among the prediction boxes , And put it with the i The prediction boxes are interchanged .
# Prediction box M, Prefix "t" Express target
tx1 = boxes[i, 0]
ty1 = boxes[i, 1]
tx2 = boxes[i, 2]
ty2 = boxes[i, 3]
ts = boxes[i, 4]
# The following for M Conduct NMS iterative process ,
# It should be noted that , If soft-NMS take score Weaken to a certain threshold threshold following , Delete it
# It is embodied in the program as , Put the box to be deleted at the end , And make N = N-1
pos = i + 1
# softNMS iteration
while pos < N:
x1 = boxes[pos, 0]
y1 = boxes[pos, 1]
x2 = boxes[pos, 2]
y2 = boxes[pos, 3]
s = boxes[pos, 4]
area = (x2 - x1 + 1) * (y2 - y1 + 1)
iw = (min(tx2, x2) - max(tx1, x1) + 1)
if iw > 0:
ih = (min(ty2, y2) - max(ty1, y1) + 1)
if ih > 0:
uinon = float((tx2 - tx1 + 1) *
(ty2 - ty1 + 1) + area - iw * ih)
iou = iw * ih / uinon # Calculation iou
if method == 1: # Linear update score
if iou > threshold1:
weight = 1 - iou
else:
weight = 1
elif method == 2: # Gaussian weight
weight = np.exp(-(iou * iou) / sigma)
else: # Tradition NMS
if iou > threshold1:
weight = 0
else:
weight = 1
boxes[pos, 4] = weight * boxes[pos, 4] # According to and the highest score box Of iou To update scores
# If box The score is too low , Abandon ( Put him last , meanwhile N-1)
if boxes[pos, 4] < threshold2:
boxes[pos, 0] = boxes[N - 1, 0]
boxes[pos, 1] = boxes[N - 1, 1]
boxes[pos, 2] = boxes[N - 1, 2]
boxes[pos, 3] = boxes[N - 1, 3]
boxes[pos, 4] = boxes[N - 1, 4]
N = N - 1 # Note that there N change
pos = pos - 1
pos = pos + 1
keep = [i for i in range(N)]
return keep
边栏推荐
- Detailed explanation of MSTP protocol for layer 3 switch configuration [Huawei ENSP experiment]
- Deconstruction assignment of ES6 variables
- 2022安全员-C证特种作业证考试题库及答案
- 力扣题(1)—— 两数之和
- IP protocol of network layer
- 负数的十六进制表示
- 站在大佬的肩膀上,你可以看的更远
- From development to testing: I started from scratch and worked for six years of automated testing
- 【杂谈】程序员的发展最需要两点能力
- 7 C控制语句:分支和跳转
猜你喜欢

Realize batch data enhancement | use of keras imagedatagenerator

正负数值的正则表达式

Machine learning: self paced and fine tuning

MDM数据质量应用说明

Vs2015 use dumpbin to view the exported function symbols of the library

IntelliJ IDEA 关联数据库

Openshift 4 - use verticalpodautoscaler to optimize application resource request and limit

实现批量数据增强 | keras ImageDataGenerator使用

【单细胞高级绘图】07.KEGG富集结果展示

网络层的IP协议
随机推荐
Hou Jie STL standard library and generic programming
OpenShift 4 之AMQ Streams(1) - 多个Consumer从Partition接收数据
Detailed explanation of DHCP distribution address of routing / layer 3 switch [Huawei ENSP]
Sword finger offer
10、学习MySQL LIKE 子句
Modify virtual machine IP address
C language array pointer and pointer array discrimination, analysis of memory leakage
Machine learning (11) -- time series analysis
【多线程】long和double的非原子性协定
信息学奥赛一本通 1617:转圈游戏 | 1875:【13NOIP提高组】转圈游戏 | 洛谷 P1965 [NOIP2013 提高组] 转圈游戏
看得清比走得快更重要,因为走得对才能走得远
GBase 8a如何使用使用预处理快速插入数据?
从开发转测试:我从零开始,一干就是6年的自动化测试历程
【多线程】println方法底层原理
Principle of line of sight tracking and explanation of the paper
Go interface Foundation
MDM data quality application description
Review the past and know the new MySQL isolation level
Starfish Os打造的元宇宙生态,跟MetaBell的合作只是开始
Sentry log management system installation and use tutorial