当前位置:网站首页>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
边栏推荐
- Linux initializes MySQL with fatal error: could not find my-default.cnf
- c语言数组指针和指针数组辨析,浅析内存泄漏
- The chess robot pinched the finger of a 7-year-old boy, and the pot of a software testing engineer? I smiled.
- 象棋机器人夹伤7岁男孩手指,软件测试工程师的锅?我笑了。。。
- Mongodb (compare relational database, cloud database, common command line, tutorial)
- Data analysis interview question summary
- Hundreds of billions of it operation and maintenance market has come to the era of speaking by "effect"
- TXT文本文件存储
- Mysql5.7.38 start keepalived in the container
- OpenShift 4 - 使用 VerticalPodAutoscaler 优化应用资源 Request 和 Limit
猜你喜欢

阿里云服务器搭建和宝塔面板连接

mysql主从架构 ,主库挂掉重启后,从库怎么自动连接主库

Promise learning notes

Overview of head pose estimation
![Detailed explanation of DHCP distribution address of routing / layer 3 switch [Huawei ENSP]](/img/9c/b4ebe608cf639b8348adc1f1cc71c8.png)
Detailed explanation of DHCP distribution address of routing / layer 3 switch [Huawei ENSP]

c语言数组指针和指针数组辨析,浅析内存泄漏

DIY system home page, your personalized needs PRO system to meet!

What are the main uses of digital factory management system

训练一个自己的分类 | 【包教包会,数据都准备好了】
![[附下载]推荐几款暴力破解和字典生成的工具](/img/c6/f4a9c566ff21a8e133a8a991108201.png)
[附下载]推荐几款暴力破解和字典生成的工具
随机推荐
IDC脚本文件运行
2022年安全员-B证考试模拟100题及答案
js数组去重,id相同对某值相加合并
TXT text file storage
Data analysis interview question summary
sql server 的关键字在哪张系统表?
Path and attribute labels of picture labels
Promise learning notes
Sentinel
推荐一个摆脱变量名纠结的神器和批量修改文件名方法
Code management platform SVN deployment practice
OpenShift 4 - 使用 VerticalPodAutoscaler 优化应用资源 Request 和 Limit
linux初始化mysql时报错 FATAL ERROR: Could not find my-default.cnf
【多线程】println方法底层原理
(IROS 2022) 基于事件相机的单目视觉惯性里程计 / Event-based Monocular Visual Inertial Odometry
【高数】高数平面立体几何
An entry artifact tensorflowplayground
Go synergy
台大林轩田《机器学习基石》习题解答和代码实现 | 【你值得拥有】
A perfect cross compilation environment records the shell scripts generated by PETA