diff --git a/model.py b/model.py index 8ae51e350a65382a1487922048916706f579d72f..e45dae91fdbf2f62ce07dc9aae377df5ae81b479 100644 --- a/model.py +++ b/model.py @@ -1409,15 +1409,14 @@ def build_detection_targets(rpn_rois, gt_class_ids, gt_boxes, gt_masks, config): # Resize mini mask to size of GT box placeholder[gt_y1:gt_y2, gt_x1:gt_x2] = \ np.round(skimage.transform.resize( - class_mask, (gt_h, gt_w), order=1, mode="reflect")).astype(bool) + class_mask, (gt_h, gt_w), order=1)).astype(bool) # Place the mini batch in the placeholder class_mask = placeholder # Pick part of the mask and resize it y1, x1, y2, x2 = rois[i].astype(np.int32) m = class_mask[y1:y2, x1:x2] - mask = skimage.transform.resize(m, config.MASK_SHAPE, - order=1, mode="reflect") + mask = skimage.transform.resize(m, config.MASK_SHAPE, order=1) masks[i, :, :, class_id] = mask return rois, roi_gt_class_ids, bboxes, masks diff --git a/utils.py b/utils.py index 71eb7b8aec095c35826ea08f4b42b5c97c5aa411..7ed2fe15a3e2e636381965b9bd6c2be8f8c25ca0 100644 --- a/utils.py +++ b/utils.py @@ -468,7 +468,8 @@ def minimize_mask(bbox, mask, mini_shape): m = m[y1:y2, x1:x2] if m.size == 0: raise Exception("Invalid bounding box with area of zero") - m = skimage.transform.resize(m, mini_shape, order=1, mode="reflect") + # Resize with bilinear interpolation + m = skimage.transform.resize(m, mini_shape, order=1) mini_mask[:, :, i] = np.around(m).astype(np.bool) return mini_mask @@ -485,7 +486,8 @@ def expand_mask(bbox, mini_mask, image_shape): y1, x1, y2, x2 = bbox[i][:4] h = y2 - y1 w = x2 - x1 - m = skimage.transform.resize(m, (h, w), order=1, mode="reflect") + # Resize with bilinear interpolation + m = skimage.transform.resize(m, (h, w), order=1) mask[y1:y2, x1:x2, i] = np.around(m).astype(np.bool) return mask @@ -505,12 +507,11 @@ def unmold_mask(mask, bbox, image_shape): """ threshold = 0.5 y1, x1, y2, x2 = bbox - mask = skimage.transform.resize(mask, (y2 - y1, x2 - x1), - order=1, mode="reflect") - mask = np.where(mask >= threshold, 1, 0).astype(np.uint8) + mask = skimage.transform.resize(mask, (y2 - y1, x2 - x1), order=1) + mask = np.where(mask >= threshold, 1, 0).astype(np.bool) # Put the mask in the right location. - full_mask = np.zeros(image_shape[:2], dtype=np.uint8) + full_mask = np.zeros(image_shape[:2], dtype=np.bool) full_mask[y1:y2, x1:x2] = mask return full_mask