(box_scores, score_threshold, sigma=0.5, top_k=-1)
Soft NMS implementation.

    References:
        https://arxiv.org/abs/1704.04503
        https://github.com/facebookresearch/Detectron/blob/master/detectron/utils/cython_nms.pyx

    Args:
        box_scores (N, 5): boxes in corner-form and probabilities.
        score_threshold: boxes with scores less than value are not considered.
        sigma: the parameter in score re-computation.
            scores[i] = scores[i] * exp(-(iou_i)^2 / simga)
        top_k: keep top_k results. If k <= 0, keep all the results.
    Returns:
         picked_box_scores (K, 5): results of NMS.
Soft NMS implementation.
Soft NMS implementation .
def soft_nms(box_scores, score_threshold, sigma=0.5, top_k=-1):
    """Soft NMS implementation.

    References:
        https://arxiv.org/abs/1704.04503
        https://github.com/facebookresearch/Detectron/blob/master/detectron/utils/cython_nms.pyx

    Args:
        box_scores (N, 5): boxes in corner-form and probabilities.
        score_threshold: boxes with scores less than value are not considered.
        sigma: the parameter in score re-computation.
            scores[i] = scores[i] * exp(-(iou_i)^2 / simga)
        top_k: keep top_k results. If k <= 0, keep all the results.
    Returns:
         picked_box_scores (K, 5): results of NMS.
    """
    picked_box_scores = []
    while box_scores.size(0) > 0:
        max_score_index = torch.argmax(box_scores[:, 4])
        cur_box_prob = torch.tensor(box_scores[max_score_index, :])
        picked_box_scores.append(cur_box_prob)
        if len(picked_box_scores) == top_k > 0 or box_scores.size(0) == 1:
            break
        cur_box = cur_box_prob[:-1]
        box_scores[max_score_index, :] = box_scores[-1, :]
        box_scores = box_scores[:-1, :]
        ious = iou_of(cur_box.unsqueeze(0), box_scores[:, :-1])
        box_scores[:, -1] = box_scores[:, -1] * torch.exp(-(ious * ious) / sigma)
        box_scores = box_scores[box_scores[:, -1] > score_threshold, :]
    if len(picked_box_scores) > 0:
        return torch.stack(picked_box_scores)
    else:
        return torch.tensor([])
def soft_nms ( box_scores , score_threshold , sigma = 0.5 , top_k = - 1 ) : picked_box_scores = [ ] while box_scores . size ( 0 ) > 0 : max_score_index = torch . argmax ( box_scores [ : , 4 ] ) cur_box_prob = torch . tensor ( box_scores [ max_score_index , : ] ) picked_box_scores . append ( cur_box_prob ) if len ( picked_box_scores ) == top_k > 0 or box_scores . size ( 0 ) == 1 : break cur_box = cur_box_prob [ : - 1 ] box_scores [ max_score_index , : ] = box_scores [ - 1 , : ] box_scores = box_scores [ : - 1 , : ] ious = iou_of ( cur_box . unsqueeze ( 0 ) , box_scores [ : , : - 1 ] ) box_scores [ : , - 1 ] = box_scores [ : , - 1 ] * torch . exp ( - ( ious * ious ) / sigma ) box_scores = box_scores [ box_scores [ : , - 1 ] > score_threshold , : ] if len ( picked_box_scores ) > 0 : return torch . stack ( picked_box_scores ) else : return torch . tensor ( [ ] )