diff --git a/mindyolo/utils/metrics.py b/mindyolo/utils/metrics.py index 8b9745cb..09de9fe1 100644 --- a/mindyolo/utils/metrics.py +++ b/mindyolo/utils/metrics.py @@ -145,17 +145,14 @@ def scale_coords(img1_shape, coords, img0_shape, ratio=None, pad=None): coords[:, [1, 3]] -= padh # y padding coords[:, [0, 2]] /= ratio # x rescale coords[:, [1, 3]] /= ratio # y rescale - coords = _clip_coords(coords, img0_shape) + _clip_coords(coords, img0_shape) return coords def _clip_coords(boxes, img_shape): # Clip bounding xyxy bounding boxes to image shape (height, width) - boxes[:, 0].clip(0, img_shape[1]) # x1 - boxes[:, 1].clip(0, img_shape[0]) # y1 - boxes[:, 2].clip(0, img_shape[1]) # x2 - boxes[:, 3].clip(0, img_shape[0]) # y2 - return boxes + boxes[..., [0, 2]] = boxes[..., [0, 2]].clip(0, img_shape[1]) # x1, x2 + boxes[..., [1, 3]] = boxes[..., [1, 3]].clip(0, img_shape[0]) # y1, y2 def _nms(xyxys, scores, threshold): diff --git a/test.py b/test.py index 7e982622..c81f11f9 100644 --- a/test.py +++ b/test.py @@ -194,7 +194,7 @@ def test_detect( # Predictions predn = np.copy(pred) - scale_coords( + predn[:, :4] = scale_coords( imgs[si].shape[1:], predn[:, :4], ori_shape[si], ratio=hw_scale[si], pad=pad[si] ) # native-space pred