Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix clamp range #288

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions test_widerface.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@ def scale_coords_landmarks(img1_shape, coords, img0_shape, ratio_pad=None):
coords[:, [1, 3, 5, 7, 9]] -= pad[1] # y padding
coords[:, :10] /= gain
#clip_coords(coords, img0_shape)
coords[:, 0].clamp_(0, img0_shape[1]) # x1
coords[:, 1].clamp_(0, img0_shape[0]) # y1
coords[:, 2].clamp_(0, img0_shape[1]) # x2
coords[:, 3].clamp_(0, img0_shape[0]) # y2
coords[:, 4].clamp_(0, img0_shape[1]) # x3
coords[:, 5].clamp_(0, img0_shape[0]) # y3
coords[:, 6].clamp_(0, img0_shape[1]) # x4
coords[:, 7].clamp_(0, img0_shape[0]) # y4
coords[:, 8].clamp_(0, img0_shape[1]) # x5
coords[:, 9].clamp_(0, img0_shape[0]) # y5
coords[:, 0].clamp_(0, img0_shape[1] - 1) # x1
coords[:, 1].clamp_(0, img0_shape[0] - 1) # y1
coords[:, 2].clamp_(0, img0_shape[1] - 1) # x2
coords[:, 3].clamp_(0, img0_shape[0] - 1) # y2
coords[:, 4].clamp_(0, img0_shape[1] - 1) # x3
coords[:, 5].clamp_(0, img0_shape[0] - 1) # y3
coords[:, 6].clamp_(0, img0_shape[1] - 1) # x4
coords[:, 7].clamp_(0, img0_shape[0] - 1) # y4
coords[:, 8].clamp_(0, img0_shape[1] - 1) # x5
coords[:, 9].clamp_(0, img0_shape[0] - 1) # y5
return coords

def show_results(img, xywh, conf, landmarks, class_num):
Expand Down
8 changes: 4 additions & 4 deletions utils/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,10 @@ def scale_coords(img1_shape, coords, img0_shape, ratio_pad=None):

def clip_coords(boxes, img_shape):
# Clip bounding xyxy bounding boxes to image shape (height, width)
boxes[:, 0].clamp_(0, img_shape[1]) # x1
boxes[:, 1].clamp_(0, img_shape[0]) # y1
boxes[:, 2].clamp_(0, img_shape[1]) # x2
boxes[:, 3].clamp_(0, img_shape[0]) # y2
boxes[:, 0].clamp_(0, img_shape[1] - 1) # x1
boxes[:, 1].clamp_(0, img_shape[0] - 1) # y1
boxes[:, 2].clamp_(0, img_shape[1] - 1) # x2
boxes[:, 3].clamp_(0, img_shape[0] - 1) # y2


def bbox_iou(box1, box2, x1y1x2y2=True, GIoU=False, DIoU=False, CIoU=False, eps=1e-9):
Expand Down