Skip to content

Commit

Permalink
New visualization: GT and predictions on one image
Browse files Browse the repository at this point in the history
Instead of showing GT and detections on two images
display_differences() shows them on the same image
for comparison.
  • Loading branch information
waleedka committed Apr 9, 2018
1 parent 9610fa5 commit 86484e5
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion mrcnn/visualize.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,45 @@ def display_instances(image, boxes, masks, class_ids, class_names,
ax.add_patch(p)
ax.imshow(masked_image.astype(np.uint8))
plt.show()



def display_differences(image,
gt_box, gt_class_id, gt_mask,
pred_box, pred_class_id, pred_score, pred_mask,
class_names, title="", ax=None,
show_mask=True, show_box=True,
iou_threshold=0.5, score_threshold=0.5):
"""Display ground truth and prediction instances on the same image."""
# Match predictions to ground truth
gt_match, pred_match, overlaps = utils.compute_matches(
gt_box, gt_class_id, gt_mask,
pred_box, pred_class_id, pred_score, pred_mask,
iou_threshold=iou_threshold, score_threshold=score_threshold)
# Ground truth = green. Predictions = red
colors = [(0, 1, 0, .8)] * len(gt_match)\
+ [(1, 0, 0, 1)] * len(pred_match)
# Concatenate GT and predictions
class_ids = np.concatenate([gt_class_id, pred_class_id])
scores = np.concatenate([np.zeros([len(gt_match)]), pred_score])
boxes = np.concatenate([gt_box, pred_box])
masks = np.concatenate([gt_mask, pred_mask], axis=-1)
# Captions per instance show score/IoU
captions = ["" for m in gt_match] + ["{:.2f} / {:.2f}".format(
r['scores'][i],
(overlaps[i, int(pred_match[i])]
if pred_match[i] > -1 else overlaps[i].max()))
for i in range(len(pred_match))]
# Set title if not provided
title = title or "Ground Truth and Detections\n GT=green, pred=red, captions: score/IoU"
# Display
display_instances(
image,
boxes, masks, class_ids,
class_names, scores, ax=ax,
show_bbox=show_box, show_mask=show_mask,
colors=colors, captions=captions,
title=title)


def draw_rois(image, rois, refined_rois, mask, class_ids, class_names, limit=10):
"""
Expand Down

0 comments on commit 86484e5

Please sign in to comment.