簡體   English   中英

快速NMS算法可抑制沒有重疊的盒子

[英]Fast NMS algorithm suppresses boxes without overlap

我正在測試Malisiewicz等人Fast NMS算法 我在遍歷示例時注意到,在一種情況下,如果我輸入兩個沒有重疊的特定框,並且IoU閾值低於0.75,則無論如何都將抑制一個框。

我誤會了NMS嗎? 我認為,如果IoU閾值設置在什么位置,如果它們之間的重疊為零,則不應丟棄任何盒子。

例:

import numpy as np

def non_max_suppression_fast(boxes, overlapThresh):

    # if there are no boxes, return an empty list
    if len(boxes) == 0:
        return []

    # initialize the list of picked indexes
    pick = []

    # grab the coordinates of the bounding boxes
    x1 = boxes[:,0]
    y1 = boxes[:,1]
    x2 = boxes[:,2]
    y2 = boxes[:,3]

    # compute the area of the bounding boxes and sort the bounding
    # boxes by the bottom-right y-coordinate of the bounding box
    area = (x2 - x1 + 1) * (y2 - y1 + 1)

    idxs = np.argsort(y2)

    # keep looping while some indexes still remain in the indexes
    # list
    while len(idxs) > 0:
        # grab the last index in the indexes list and add the
        # index value to the list of picked indexes
        last = len(idxs) - 1
        i = idxs[last]
        pick.append(i)

        # find the largest (x, y) coordinates for the start of
        # the bounding box and the smallest (x, y) coordinates
        # for the end of the bounding box
        xx1 = np.maximum(x1[i], x1[idxs[:last]])
        yy1 = np.maximum(y1[i], y1[idxs[:last]])
        xx2 = np.minimum(x2[i], x2[idxs[:last]])
        yy2 = np.minimum(y2[i], y2[idxs[:last]])

        # compute the width and height of the bounding box
        w = np.maximum(0, xx2 - xx1 + 1)
        h = np.maximum(0, yy2 - yy1 + 1)

        # compute the ratio of overlap
        overlap = (w * h) / area[idxs[:last]]

        # delete all indexes from the index list that have
        idxs = np.delete(idxs, np.concatenate(([last],
            np.where(overlap > overlapThresh)[0])))

    # return only the bounding boxes that were picked
    return boxes[pick]


# Two test boxes
                   #xmin,ymin,xmax,ymax
boxes = np.vstack([[0.3, 0.2, 0.4, 0.5], 
                  [0.1, 0.1, 0.2, 0.2]])


# no box suppression
print(non_max_suppression_fast(boxes, overlapThresh=.75))

# one box is suppressed
print(non_max_suppression_fast(boxes, overlapThresh=.74))

您的輸入測試用例不合法,參數boxes期望框的坐標為絕對格式,例如像素坐標。

您會注意到,在計算所有框的面積時,

area = (x2 - x1 + 1) * (y2 - y1 + 1)

+1是增加的像素,請確保area是該框占用的實際像素數。

嘗試這個:

boxes = np.vstack([[3, 2, 4, 5], 
              [1, 1, 2, 2]])

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM