From a593c301484cdad30fcf811ffd62dd6684e83b5f Mon Sep 17 00:00:00 2001 From: Waleed Abdulla Date: Tue, 5 Jun 2018 00:20:07 -0700 Subject: [PATCH] Fix: color_splash when no masks are detected Reported here: https://github.com/matterport/Mask_RCNN/pull/500 --- mrcnn/model.py | 2 +- samples/balloon/balloon.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/mrcnn/model.py b/mrcnn/model.py index caf7fb5..7d44bdc 100644 --- a/mrcnn/model.py +++ b/mrcnn/model.py @@ -2429,7 +2429,7 @@ class MaskRCNN(): full_mask = utils.unmold_mask(masks[i], boxes[i], original_image_shape) full_masks.append(full_mask) full_masks = np.stack(full_masks, axis=-1)\ - if full_masks else np.empty(masks.shape[1:3] + (0,)) + if full_masks else np.empty(original_image_shape[:2] + (0,)) return boxes, class_ids, scores, full_masks diff --git a/samples/balloon/balloon.py b/samples/balloon/balloon.py index 18b237f..0fbd2d2 100644 --- a/samples/balloon/balloon.py +++ b/samples/balloon/balloon.py @@ -204,13 +204,13 @@ def color_splash(image, mask): # Make a grayscale copy of the image. The grayscale copy still # has 3 RGB channels, though. gray = skimage.color.gray2rgb(skimage.color.rgb2gray(image)) * 255 - # We're treating all instances as one, so collapse the mask into one layer - mask = (np.sum(mask, -1, keepdims=True) >= 1) # Copy color pixels from the original color image where mask is set - if mask.shape[0] > 0: + if mask.shape[-1] > 0: + # We're treating all instances as one, so collapse the mask into one layer + mask = (np.sum(mask, -1, keepdims=True) >= 1) splash = np.where(mask, image, gray).astype(np.uint8) else: - splash = gray + splash = gray.astype(np.uint8) return splash -- GitLab