Skip to content

Commit

Permalink
Fix filtering out detections with area==0.
Browse files Browse the repository at this point in the history
  • Loading branch information
waleedka committed Nov 26, 2017
1 parent f448a5d commit 46f8ea5
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -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):
Expand Down

0 comments on commit 46f8ea5

Please sign in to comment.