From 46f8ea594c11e2d844aa37e239a1e882f766acc5 Mon Sep 17 00:00:00 2001 From: Waleed Abdulla Date: Sat, 25 Nov 2017 19:22:36 -0800 Subject: [PATCH] Fix filtering out detections with area==0. --- model.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/model.py b/model.py index 306ead7f9a..76bb24744b 100644 --- a/model.py +++ b/model.py @@ -2269,17 +2269,6 @@ def unmold_detections(self, detections, mrcnn_mask, image_shape, window): scores = detections[:N, 5] masks = mrcnn_mask[np.arange(N), :, :, class_ids] - # Filter out detections with zero area. Often only happens in early - # stages of training when the network weights are still a bit random. - exclude_ix = np.where( - (boxes[:, 2] - boxes[:, 0]) * (boxes[:, 2] - boxes[:, 0]) <= 0)[0] - if exclude_ix.shape[0] > 0: - boxes = np.delete(boxes, exclude_ix, axis=0) - class_ids = np.delete(class_ids, exclude_ix, axis=0) - scores = np.delete(scores, exclude_ix, axis=0) - masks = np.delete(masks, exclude_ix, axis=0) - N = class_ids.shape[0] - # Compute scale and shift to translate coordinates to image domain. h_scale = image_shape[0] / (window[2] - window[0]) w_scale = image_shape[1] / (window[3] - window[1]) @@ -2291,6 +2280,17 @@ def unmold_detections(self, detections, mrcnn_mask, image_shape, window): # Translate bounding boxes to image domain boxes = np.multiply(boxes - shifts, scales).astype(np.int32) + # Filter out detections with zero area. Often only happens in early + # stages of training when the network weights are still a bit random. + exclude_ix = np.where( + (boxes[:, 2] - boxes[:, 0]) * (boxes[:, 3] - boxes[:, 1]) <= 0)[0] + if exclude_ix.shape[0] > 0: + boxes = np.delete(boxes, exclude_ix, axis=0) + class_ids = np.delete(class_ids, exclude_ix, axis=0) + scores = np.delete(scores, exclude_ix, axis=0) + masks = np.delete(masks, exclude_ix, axis=0) + N = class_ids.shape[0] + # Resize masks to original image size and set boundary threshold. full_masks = [] for i in range(N):