1010from sahi .utils .import_utils import check_requirements
1111
1212
13- def batched_nms (predictions : torch .tensor , match_metric : str = "IOU" , match_threshold : float = 0.5 ):
13+ def batched_nms (predictions : torch .Tensor , match_metric : str = "IOU" , match_threshold : float = 0.5 ) -> list [ int ] :
1414 """Apply non-maximum suppression to avoid detecting too many overlapping bounding boxes for a given object.
1515
1616 Args:
@@ -40,7 +40,7 @@ def nms(
4040 predictions : torch .Tensor ,
4141 match_metric : str = "IOU" ,
4242 match_threshold : float = 0.5 ,
43- ):
43+ ) -> list [ int ] :
4444 """
4545 Optimized non-maximum suppression for axis-aligned bounding boxes using STRTree.
4646
@@ -145,10 +145,10 @@ def nms(
145145
146146
147147def batched_greedy_nmm (
148- object_predictions_as_tensor : torch .tensor ,
148+ object_predictions_as_tensor : torch .Tensor ,
149149 match_metric : str = "IOU" ,
150150 match_threshold : float = 0.5 ,
151- ):
151+ ) -> dict [ int , list [ int ]] :
152152 """Apply greedy version of non-maximum merging per category to avoid detecting too many overlapping bounding boxes
153153 for a given object.
154154
@@ -159,7 +159,7 @@ def batched_greedy_nmm(
159159 match_threshold: (float) The overlap thresh for
160160 match metric.
161161 Returns:
162- keep_to_merge_list: (Dict [int:List [int]]) mapping from prediction indices
162+ keep_to_merge_list: (dict [int, list [int]]) mapping from prediction indices
163163 to keep to a list of prediction indices to be merged.
164164 """
165165 category_ids = object_predictions_as_tensor [:, 5 ].squeeze ()
@@ -179,7 +179,7 @@ def greedy_nmm(
179179 object_predictions_as_tensor : torch .Tensor ,
180180 match_metric : str = "IOU" ,
181181 match_threshold : float = 0.5 ,
182- ):
182+ ) -> dict [ int , list [ int ]] :
183183 """
184184 Optimized greedy non-maximum merging for axis-aligned bounding boxes using STRTree.
185185
@@ -290,7 +290,7 @@ def batched_nmm(
290290 object_predictions_as_tensor : torch .Tensor ,
291291 match_metric : str = "IOU" ,
292292 match_threshold : float = 0.5 ,
293- ):
293+ ) -> dict [ int , list [ int ]] :
294294 """Apply non-maximum merging per category to avoid detecting too many overlapping bounding boxes for a given object.
295295
296296 Args:
@@ -300,7 +300,7 @@ def batched_nmm(
300300 match_threshold: (float) The overlap thresh for
301301 match metric.
302302 Returns:
303- keep_to_merge_list: (Dict [int:List [int]]) mapping from prediction indices
303+ keep_to_merge_list: (dict [int, list [int]]) mapping from prediction indices
304304 to keep to a list of prediction indices to be merged.
305305 """
306306 category_ids = object_predictions_as_tensor [:, 5 ].squeeze ()
@@ -320,7 +320,7 @@ def nmm(
320320 object_predictions_as_tensor : torch .Tensor ,
321321 match_metric : str = "IOU" ,
322322 match_threshold : float = 0.5 ,
323- ):
323+ ) -> dict [ int , list [ int ]] :
324324 """Apply non-maximum merging to avoid detecting too many overlapping bounding boxes for a given object.
325325
326326 Args:
@@ -329,7 +329,7 @@ def nmm(
329329 match_metric: (str) IOU or IOS
330330 match_threshold: (float) The overlap thresh for match metric.
331331 Returns:
332- keep_to_merge_list: (Dict [int:List [int]]) mapping from prediction indices
332+ keep_to_merge_list: (dict [int, list [int]]) mapping from prediction indices
333333 to keep to a list of prediction indices to be merged.
334334 """
335335 # Extract coordinates and scores as tensors
@@ -460,15 +460,15 @@ def __init__(
460460
461461 check_requirements (["torch" ])
462462
463- def __call__ (self , predictions : list [ObjectPrediction ]):
463+ def __call__ (self , predictions : list [ObjectPrediction ]) -> list [ ObjectPrediction ] :
464464 raise NotImplementedError ()
465465
466466
467467class NMSPostprocess (PostprocessPredictions ):
468468 def __call__ (
469469 self ,
470470 object_predictions : list [ObjectPrediction ],
471- ):
471+ ) -> list [ ObjectPrediction ] :
472472 object_prediction_list = ObjectPredictionList (object_predictions )
473473 object_predictions_as_torch = object_prediction_list .totensor ()
474474 if self .class_agnostic :
@@ -491,7 +491,7 @@ class NMMPostprocess(PostprocessPredictions):
491491 def __call__ (
492492 self ,
493493 object_predictions : list [ObjectPrediction ],
494- ):
494+ ) -> list [ ObjectPrediction ] :
495495 object_prediction_list = ObjectPredictionList (object_predictions )
496496 object_predictions_as_torch = object_prediction_list .totensor ()
497497 if self .class_agnostic :
@@ -528,7 +528,7 @@ class GreedyNMMPostprocess(PostprocessPredictions):
528528 def __call__ (
529529 self ,
530530 object_predictions : list [ObjectPrediction ],
531- ):
531+ ) -> list [ ObjectPrediction ] :
532532 object_prediction_list = ObjectPredictionList (object_predictions )
533533 object_predictions_as_torch = object_prediction_list .totensor ()
534534 if self .class_agnostic :
@@ -566,7 +566,7 @@ class LSNMSPostprocess(PostprocessPredictions):
566566 def __call__ (
567567 self ,
568568 object_predictions : list [ObjectPrediction ],
569- ):
569+ ) -> list [ ObjectPrediction ] :
570570 try :
571571 from lsnms import nms
572572 except ModuleNotFoundError :
0 commit comments