@@ -105,24 +105,54 @@ def _resize_detections(self, detections, meta):
105105 pad_top = (self .h - round (input_img_height / inverted_scale_y )) // 2
106106
107107 for detection in detections :
108- detection .xmin = min (
109- max (round ((detection .xmin * self .w - pad_left ) * inverted_scale_x ), 0 ),
110- input_img_widht ,
108+ detection .xmin = round (
109+ min (
110+ max ((detection .xmin * self .w - pad_left ) * inverted_scale_x , 0 ),
111+ input_img_widht ,
112+ )
111113 )
112- detection .ymin = min (
113- max (round ((detection .ymin * self .h - pad_top ) * inverted_scale_y ), 0 ),
114- input_img_height ,
114+ detection .ymin = round (
115+ min (
116+ max ((detection .ymin * self .h - pad_top ) * inverted_scale_y , 0 ),
117+ input_img_height ,
118+ )
115119 )
116- detection .xmax = min (
117- max (round ((detection .xmax * self .w - pad_left ) * inverted_scale_x ), 0 ),
118- input_img_widht ,
120+ detection .xmax = round (
121+ min (
122+ max ((detection .xmax * self .w - pad_left ) * inverted_scale_x , 0 ),
123+ input_img_widht ,
124+ )
119125 )
120- detection .ymax = min (
121- max (round ((detection .ymax * self .h - pad_top ) * inverted_scale_y ), 0 ),
122- input_img_height ,
126+ detection .ymax = round (
127+ min (
128+ max ((detection .ymax * self .h - pad_top ) * inverted_scale_y , 0 ),
129+ input_img_height ,
130+ )
123131 )
124132 return detections
125133
134+ def _filter_detections (self , detections , box_area_threshold = 0 ):
135+ """Filters detections by confidence threshold and box size threshold
136+
137+ Args:
138+ detections (List[Detection]): list of detections with coordinates in normalized form
139+ box_area_threshold (float): minimal area of the bounding to be considered
140+
141+ Returns:
142+ - list of detections with confidence above the threshold
143+ """
144+ filtered_detections = []
145+ for detection in detections :
146+ if (
147+ detection .score < self .confidence_threshold
148+ or (detection .xmax - detection .xmin ) * (detection .ymax - detection .ymin )
149+ < box_area_threshold
150+ ):
151+ continue
152+ filtered_detections .append (detection )
153+
154+ return filtered_detections
155+
126156 def _add_label_names (self , detections ):
127157 """Adds labels names to detections if they are available
128158
0 commit comments