utils.clip_coords doesn't work as expected. (#961)

* utils.clip_coords doesn't work as expected.

Box coords may be negative or exceed borders.

* Update utils.py

Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
This commit is contained in:
GoogleWiki 2020-03-28 04:09:10 +08:00 committed by GitHub
parent 4a63b24b09
commit 582de735ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 2 deletions

View File

@ -160,8 +160,10 @@ def scale_coords(img1_shape, coords, img0_shape, ratio_pad=None):
def clip_coords(boxes, img_shape): def clip_coords(boxes, img_shape):
# Clip bounding xyxy bounding boxes to image shape (height, width) # Clip bounding xyxy bounding boxes to image shape (height, width)
boxes[:, [0, 2]].clamp_(0, img_shape[1]) # clip x boxes[:, 0].clamp_(0, img_shape[1]) # x1
boxes[:, [1, 3]].clamp_(0, img_shape[0]) # clip y boxes[:, 1].clamp_(0, img_shape[0]) # y1
boxes[:, 2].clamp_(0, img_shape[1]) # x2
boxes[:, 3].clamp_(0, img_shape[0]) # y2
def ap_per_class(tp, conf, pred_cls, target_cls): def ap_per_class(tp, conf, pred_cls, target_cls):