提交 38ed3398 编写于 作者: W Waleed Abdulla

Fix mask resizing crash with tiny masks.

skimage.transform.resize() crashes with a floating
point exception if the image has 1-pixel width or
height and the mode=“reflection”. Changing mode to
“constant” (the default) fixes the issue. And, 
it’s the correct mode to use anyway.
上级 dffcb611
......@@ -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
......
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册