Skip to content

Commit

Permalink
modify _clip_coords to in-place operation
Browse files Browse the repository at this point in the history
  • Loading branch information
yuedongli1 committed Oct 13, 2023
1 parent f8bd518 commit 9c264b0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
9 changes: 3 additions & 6 deletions mindyolo/utils/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 9c264b0

Please sign in to comment.