[Fix] Fix ppyoloerandomcrop (#817)

* fix ppyoloerandomcrop

* fix maskrefine

---------

Co-authored-by: Lingrui Gu <lingrui.gu@nanovision.com.cn>
pull/851/head
Nioolek 2023-07-19 11:34:45 +08:00 committed by GitHub
parent 106bec4edc
commit 85958c82e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 4 deletions

View File

@ -793,6 +793,7 @@ class YOLOv5RandomAffine(BaseTransform):
num_bboxes = len(bboxes)
if num_bboxes:
orig_bboxes = bboxes.clone()
orig_bboxes.rescale_([scaling_ratio, scaling_ratio])
if 'gt_masks' in results:
# If the dataset has annotations of mask,
# the mask will be used to refine bbox.
@ -817,8 +818,6 @@ class YOLOv5RandomAffine(BaseTransform):
bboxes.clip_([height, width])
# filter bboxes
orig_bboxes.rescale_([scaling_ratio, scaling_ratio])
# Be careful: valid_index must convert to numpy,
# otherwise it will raise out of bounds when len(valid_index)=1
valid_index = self.filter_gt_bboxes(orig_bboxes,
@ -1499,8 +1498,8 @@ class PPYOLOERandomCrop(BaseTransform):
overlap = np.prod(
rightbottom - lefttop,
axis=2) * (lefttop < rightbottom).all(axis=2)
area_gt_bbox = np.prod(gt_bbox[:, 2:] - crop_bbox[:, :2], axis=1)
area_crop_bbox = np.prod(gt_bbox[:, 2:] - crop_bbox[:, :2], axis=1)
area_gt_bbox = np.prod(gt_bbox[:, 2:] - gt_bbox[:, :2], axis=1)
area_crop_bbox = np.prod(crop_bbox[:, 2:] - crop_bbox[:, :2], axis=1)
area_o = (area_gt_bbox[:, np.newaxis] + area_crop_bbox - overlap)
return overlap / (area_o + eps)