当前位置:网站首页>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
边栏推荐
- 如何在多线程环境下使用 GBase C API ?
- 信息学奥赛一本通 1617:转圈游戏 | 1875:【13NOIP提高组】转圈游戏 | 洛谷 P1965 [NOIP2013 提高组] 转圈游戏
- Mysql5.7.38 start keepalived in the container
- Starfish Os打造的元宇宙生态,跟MetaBell的合作只是开始
- linux初始化mysql时报错 FATAL ERROR: Could not find my-default.cnf
- Learn to draw with nature communications -- complex violin drawing
- 【多线程】long和double的非原子性协定
- Linux initializes MySQL with fatal error: could not find my-default.cnf
- Review the past and know the new MySQL isolation level
- JSON 文件存储
猜你喜欢
随机推荐
Train your own classification [Bao Jiaobao, the data are ready]
JSON file storage
ES6 变量的解构赋值
2022年安全员-B证考试模拟100题及答案
2022高压电工考试模拟100题及模拟考试
完善的交叉编译环境记录 peta 生成的shell 脚本
3D全景展示新模式,成为破局的关键
Prometheus TSDB analysis
Go panic and recover
Linux initializes MySQL with fatal error: could not find my-default.cnf
LeetCode_406_根据身高重建队列
VS2015使用dumpbin 查看库的导出函数符号
台大林轩田《机器学习基石》习题解答和代码实现 | 【你值得拥有】
2022安全员-C证特种作业证考试题库及答案
C#简单调用FMU ,进行仿真计算
AMQ streams (1) of openshift 4 - multiple consumers receive data from partition
shell 实现harbor v1/v2的备份/恢复/迁移等功能
Magic Bracelet-【群论】【Burnside引理】【矩阵快速幂】
C simply call FMU for simulation calculation
Leetcode 452. minimum number of arrows to burst balloons (medium)








