@@ -104,34 +104,34 @@ def _resize_detections(self, detections, meta):
104104 pad_left = (self .w - round (input_img_widht / inverted_scale_x )) // 2
105105 pad_top = (self .h - round (input_img_height / inverted_scale_y )) // 2
106106
107+ def _clamp_and_round (val , min_value , max_value ):
108+ return round (max (min_value , min (max_value , val )))
109+
107110 for detection in detections :
108- detection .xmin = round (
109- min (
110- max ((detection .xmin * self .w - pad_left ) * inverted_scale_x , 0 ),
111- input_img_widht ,
112- )
111+ detection .xmin = _clamp_and_round (
112+ (detection .xmin * self .w - pad_left ) * inverted_scale_x ,
113+ 0 ,
114+ input_img_widht ,
113115 )
114- detection .ymin = round (
115- min (
116- max ((detection .ymin * self .h - pad_top ) * inverted_scale_y , 0 ),
117- input_img_height ,
118- )
116+ detection .ymin = _clamp_and_round (
117+ (detection .ymin * self .h - pad_top ) * inverted_scale_y ,
118+ 0 ,
119+ input_img_height ,
119120 )
120- detection .xmax = round (
121- min (
122- max ((detection .xmax * self .w - pad_left ) * inverted_scale_x , 0 ),
123- input_img_widht ,
124- )
121+ detection .xmax = _clamp_and_round (
122+ (detection .xmax * self .w - pad_left ) * inverted_scale_x ,
123+ 0 ,
124+ input_img_widht ,
125125 )
126- detection .ymax = round (
127- min (
128- max ((detection .ymax * self .h - pad_top ) * inverted_scale_y , 0 ),
129- input_img_height ,
130- )
126+ detection .ymax = _clamp_and_round (
127+ (detection .ymax * self .h - pad_top ) * inverted_scale_y ,
128+ 0 ,
129+ input_img_height ,
131130 )
131+
132132 return detections
133133
134- def _filter_detections (self , detections , box_area_threshold = 0 ):
134+ def _filter_detections (self , detections , box_area_threshold = 0.0 ):
135135 """Filters detections by confidence threshold and box size threshold
136136
137137 Args:
0 commit comments