- NMS算法:
- 代码实现
# Bounding Boxes: boxes [B1,B2,...,Bn]
# B = [x1,y1,x2,y2]
# (x1,y1)
# (x2,y2)
# Confidences: scores [S1,S2,...,Sn]
# NMS Threshold: threshold
# Outpus Boxes:keep []
def NMS(boxes, scores, threshold)
proposal = sorted(list(zip(boxes, scores)), key = lambda x:x[1], reverse = True)
keep = [ ]
while proposal:
max_proposal = proposal[0]
keep.append(proposal[0])
proposal = proposal[1:]
for index, pro in enumerate(proposal):
if IOU(max_proposal, pro) >= threshold:
proposal.pop(index)
return keep
def IOU(pro1, pro2):
box1 = pro1[0]
box2 = pro2[0]
area1 = (box1[2]-box1[0])*(box1[3]-box1[1])
area2 = (box2[2]-box2[0])*(box2[3]-box2[1])
xx1 = max(box1[0], box2[0])
yy1 = max(box1[1], box2[1]) # 找出更大的x1,y1
xx2 = min(box1[2], box2[2])
yy2 = min(box1[3], box3[3]) # 找出更小的x2,y2
w = max(0, xx2-xx1+1)
h = max(0, yy2-yy1+1)
inter = w*h
over = inter / (area1 + area2 - inter)
return over
- 可能存在的问题:NMS的阈值不容易确定,阈值太小,当两个物体的框重叠较多,可能会出现漏检;阈值太大,容易增大误检。
- 解决办法:Soft-NMS, 不直接删除所有IoU大于阈值的框,而是降低其置信度。
- mAP:
P:precision,预测正确的个数/测试总个数
AP:average precision,每一类别P值的平均值
MAP:mean average precision,对所有类别的AP取均值
(1) mAP的计算
mAP.png(2) MS COCO mAP
MS COCO mAP.png
网友评论