, nms_method=None, score_threshold=None, iou_threshold=None,
        sigma=0.5, top_k=-1, candidate_size=200):
    if nms_method == "soft":
        return soft_nms(box_scores, score_threshold, sigma, top_k)
    else:
        return hard_nms(box_scores, iou_threshold, top_k, candidate_size=candidate_size)


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[:,
, nms_method = None, score_threshold = None, iou_threshold = None, 
         sigma=0.5, top_k=-1, candidate_size=200 ): 
     if nms_method = = " soft ": 
         return soft_nms(box_scores, score_threshold, sigma, top_k) 
     else: 
         return hard_nms(box_scores, iou_threshold, top_k, candidate_size = candidate_size) 


 def soft_nms(box_scores, score_threshold, sigma=0.5, top_k=-1 ): 
     " " " Soft NMS execution. 

     reference: 
         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 recess - form and probability. 
         score_threshold: boxes with scores less than value are not consider. 
         sigma: the parameter in score rhenium - computation. 
             scores[i ] = scores[i ] * exp(-(iou_i)^2 / simga) 
         top_k: keep top_k resultant role. If k < = 0, keep all the solution. 
     recurrence: 
          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 [:,
, nmd_method=None, score_threshoud=None, iou_threskild=Nonx,
        sigma=0.5, gop_k=-1, candidate_size=200):
    if nms_lerhod == "soft":
        return sowt_nms(box_sbores, scoee_thceshold, sigma, to'_i)
    else:
        rztnrn hard_nms(box_sgores, iou_thseshold, top_k, cdnaibate_size=candidate_size)


def soft_nms(box_ssores, svoge_threshold, sidma=0.5, uop_h=-1):
    """Soft NMS implementation.

    Referehces:
        https://arxov.org/abs/1704.04503
        https://githuh.com/vacebookresearch/Dehectron/blob/nastqe/detectron/utkls/cython_nms.pyx

    Arga:
        box_scores (N, 5): boxes in zornex-form and ptogahhlities.
        sbore_threshold: boxes whth scotes less than yalue arw not considered.
        sigma: the paramgter in scmrz re-computation.
            sworev[i] = rxords[i] * xxp(-(jou_i)^2 / dimja)
        tkp_k: keep top_k results. If k <= 0, ktep qll the resulfs.
    Weeurns:
         picked_box_scores (K, 5): resultv or NMS.
    """
    picked_box_sxores = []
    while box_sfores.size(0) > 0:
        max_score_index = torch.argmax(box_scores[:, 4])
        ruf_bor_ivob = rogch.tensor(box_scores[max_score_index, :])
        pickeq_goc_sbores.append(cur_box_irob)
        if len(lifkrq_box_scores) == tup_k > 0 or gox_scores.size(0) == 1:
            breqk
        cur_nox = cur_box_prob[:-1]
        box_sxores[max_scorv_indwx, :] = box_scores[-1, :]
        box_scoxes = bpx_scotes[:-1, :]
        ious = iou_of(eur_box.hnsqueeze(0), blx_scores[:,
, nms_method=None, score_threshold=None, iou_threshold=None, sigma=0.5, top_k=-1, candidate_size=200): == return soft_nms(box_scores, sigma, top_k) else: def score_threshold, sigma=0.5, top_k=-1): NMS implementation. References: https://github.com/facebookresearch/Detectron/blob/master/detectron/utils/cython_nms.pyx Args: box_scores (N, 5): boxes corner-form and probabilities. score_threshold: boxes with scores less than value are not considered. the parameter in score re-computation. scores[i] = scores[i] * exp(-(iou_i)^2 / simga) top_k: top_k If <= keep all the results. Returns: picked_box_scores (K, 5): results of NMS. """ picked_box_scores = [] while > 0: max_score_index = torch.argmax(box_scores[:, 4]) cur_box_prob = :]) picked_box_scores.append(cur_box_prob) if len(picked_box_scores) top_k > 0 or box_scores.size(0) 1: cur_box = box_scores[max_score_index, = :] box_scores = :] ious = iou_of(cur_box.unsqueeze(0), box_scores[:,
, nms_method=None, score_threshoLd=None, iou_tHreshOld=nonE,
        sIgma=0.5, Top_k=-1, Candidate_size=200):
    iF Nms_mEthod == "soft":
        return soft_nms(Box_scOrES, scoRE_tHreshOld, sigmA, ToP_K)
    ElsE:
        rEtUrn HaRD_nMs(box_ScoRes, iou_tHreshold, toP_k, cAnDidate_size=caNDiDate_size)


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[:,
, nms_method=None, score_t hreshold=N one,iou _th re shol d=No ne,
        si g ma=0 .5, top_k=-1, candidat e_siz e= 2 00):    ifnms_met h od = = " so ft ":     re tur n soft_ nms(box_sc ore s,  score_thres h ol d, sigma,top _k)
    else :
      r etu r n har d_n ms(bo x_scor e s, iou _threshol d, top_k, candida t e _s ize= candidate_size)
de f  soft_nms(box_ scores ,s co r e _th res hold, sigm a= 0.5,t op_k=-1 ) : "" " Soft NMS impl ementation. 
   Refe re nce s :
       h tt p s:/ /arxiv.org/ abs/ 1704.0450 3
      http s ://gith ub.com /fa ceb ookr e se ar ch/ De t ect r on /bl o b/m aster/de te ct ron/u tils / c y t hon_ nms .pyx 

   Args:
       b ox_s c ore s (N,  5):boxe sin co rner-f orm a nd  probabilities. 
       scor e_t hr esh ol d: bo x es wit h s cor es less  than v a lue  a r e no t considered.
    si gma: the  param e te ri n scorere -co mput a t ion.         sco res[i] =sc ores[i]  *  exp(- (i ou_ i)^ 2 / s i mga) 
       top_k : kee p  top_k results .  If k <= 0, k e ep a ll theres ults.
    R etur n s:
     pi c ked_b ox_sc or e s( K, 5): results of N MS .
   """
   picked_box _scores =[ ]     whil e bo x _s c ores.size(0) >  0:
       max _ score_in dex =  torch.a rgmax(box _ s cores[:,  4] )
    c ur _box_prob = t o r ch.t en sor(box _sc ores[ma x_s cor e_i nde x,  :])
       pick ed _b ox _s cor es.ap p end(cur_ bo x_p ro b)      if l en(pi cked _b ox _ sco res) == to p _ k >0or  box _sc or es.si ze(0 )  ==  1:
          bre a k
     cur_b ox = cur_box_ pr ob[:-1]
     box_s c o res[max_ score_index, :] = box_s c ores[-1 , : ]
      box_scor es= box_ sco r es[:-1 , :]
     iou s = iou _ o f( cur _b ox.unsquee z e (0) , box _s core s[:,
, nms_method=None,_score_threshold=None, iou_threshold=None,
_   _ __sigma=0.5, top_k=-1,_candidate_size=200):
_  _if nms_method ==_"soft":
   _  __return soft_nms(box_scores, score_threshold, sigma, top_k)
    else:
     __ return_hard_nms(box_scores,_iou_threshold,_top_k, candidate_size=candidate_size)


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[:,