当前位置:网站首页>NMS reduction box

NMS reduction box

2022-06-25 20:06:00 Orange cedar

import numpy as np
def NMS(nums, threshold):
    x1 = nums[:, 0]
    y1 = nums[:, 1]
    x2 = nums[:, 2]
    y2 = nums[:, 3]
    area = (x2 - x1) * (y2 - y1)

    score = nums[:, 4]
    score = np.argsort(score)[::-1]
   #  The function is to x The elements in are arranged from small to large , Extract the corresponding index( Indexes ), Then output to argsort()
    keep = []
    while score.size > 0:
        #print("score=",score)
        keep.append(score[0])
        #  Calculation times greater than score All the frames with the largest score Of IOU
        xx1 = np.maximum(x1[score[0]], x1[score[1:]])  #  Be careful : Here is an iterator  for
        yy1 = np.maximum(y1[score[0]], y1[score[1:]])
        xx2 = np.minimum(x2[score[0]], x2[score[1:]])
        yy2 = np.minimum(y2[score[0]], y2[score[1:]])
        w = np.maximum(0.0, xx2 - xx1)
        h = np.maximum(0.0, yy2 - yy1)
        # IOU
        overlap = w * h
        iou = overlap/(area[score[0]] + area[score[1:]] - overlap)
        #         print("iou=",iou)
        iou_low = np.where(iou <= threshold)[0]  #  Returns all and maximum score Compared with <threshold  The subscript 
        #         print(" Find the rectangle index whose overlap is not higher than the threshold :",iou_low)
        score = score[iou_low + 1]
    return keep
原网站

版权声明
本文为[Orange cedar]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202190507547360.html