(boxes, overlap_threshold=0.5, mode='union')
return pick
Non-maximum suppression.

    Arguments:
        boxes: a float numpy array of shape [n, 5],
            where each row is (xmin, ymin, xmax, ymax, score).
        overlap_threshold: a float number.
        mode: 'union' or 'min'.

    Returns:
        list with indices of the selected boxes
Non-maximum suppression.
Non - maximum suppression .
def nms(boxes, overlap_threshold=0.5, mode='union'):
    """Non-maximum suppression.

    Arguments:
        boxes: a float numpy array of shape [n, 5],
            where each row is (xmin, ymin, xmax, ymax, score).
        overlap_threshold: a float number.
        mode: 'union' or 'min'.

    Returns:
        list with indices of the selected boxes
    """

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

    # list of picked indices
    pick = []

    # grab the coordinates of the bounding boxes
    x1, y1, x2, y2, score = [boxes[:, i] for i in range(5)]

    area = (x2 - x1 + 1.0)*(y2 - y1 + 1.0)
    ids = np.argsort(score)  # in increasing order

    while len(ids) > 0:

        # grab index of the largest value
        last = len(ids) - 1
        i = ids[last]
        pick.append(i)

        # compute intersections
        # of the box with the largest score
        # with the rest of boxes

        # left top corner of intersection boxes
        ix1 = np.maximum(x1[i], x1[ids[:last]])
        iy1 = np.maximum(y1[i], y1[ids[:last]])

        # right bottom corner of intersection boxes
        ix2 = np.minimum(x2[i], x2[ids[:last]])
        iy2 = np.minimum(y2[i], y2[ids[:last]])

        # width and height of intersection boxes
        w = np.maximum(0.0, ix2 - ix1 + 1.0)
        h = np.maximum(0.0, iy2 - iy1 + 1.0)

        # intersections' areas
        inter = w * h
        if mode == 'min':
            overlap = inter/np.minimum(area[i], area[ids[:last]])
        elif mode == 'union':
            # intersection over union (IoU)
            overlap = inter/(area[i] + area[ids[:last]] - inter)

        # delete all boxes where overlap is too big
        ids = np.delete(
            ids,
            np.concatenate([[last], np.where(overlap > overlap_threshold)[0]])
        )

    return pick
def nms ( boxes , overlap_threshold = 0.5 , mode = 'union' ) : # if there are no boxes, return the empty list if len ( boxes ) == 0 : return [ ] # list of picked indices pick = [ ] # grab the coordinates of the bounding boxes x1 , y1 , x2 , y2 , score = [ boxes [ : , i ] for i in range ( 5 ) ] area = ( x2 - x1 + 1.0 ) * ( y2 - y1 + 1.0 ) ids = np . argsort ( score ) # in increasing order while len ( ids ) > 0 : # grab index of the largest value last = len ( ids ) - 1 i = ids [ last ] pick . append ( i ) # compute intersections # of the box with the largest score # with the rest of boxes # left top corner of intersection boxes ix1 = np . maximum ( x1 [ i ] , x1 [ ids [ : last ] ] ) iy1 = np . maximum ( y1 [ i ] , y1 [ ids [ : last ] ] ) # right bottom corner of intersection boxes ix2 = np . minimum ( x2 [ i ] , x2 [ ids [ : last ] ] ) iy2 = np . minimum ( y2 [ i ] , y2 [ ids [ : last ] ] ) # width and height of intersection boxes w = np . maximum ( 0.0 , ix2 - ix1 + 1.0 ) h = np . maximum ( 0.0 , iy2 - iy1 + 1.0 ) # intersections' areas inter = w * h if mode == 'min' : overlap = inter / np . minimum ( area [ i ] , area [ ids [ : last ] ] ) elif mode == 'union' : # intersection over union (IoU) overlap = inter / ( area [ i ] + area [ ids [ : last ] ] - inter ) # delete all boxes where overlap is too big ids = np . delete ( ids , np . concatenate ( [ [ last ] , np . where ( overlap > overlap_threshold ) [ 0 ] ] ) ) return pick