提交 459dbb74 编写于 作者: W Waleed Abdulla

Remove display_detections(). Not used.

上级 677eeb79
......@@ -219,64 +219,6 @@ def draw_box(image, box, color):
return image
def display_detections(image, gt_boxes, boxes, masks, class_ids, class_names, scores=None):
"""
boxes: [num_instance, (y1, x1, y2, x2, class_id)] in image coordinates.
masks: [num_instances, height, width]
class_ids: [num_instances]
class_names: list of class names of the dataset
scores: (optional) confidence scores for each box
"""
assert boxes.shape[0] == masks.shape[-1] == class_ids.shape[0]
fig, ax = plt.subplots(1, figsize=(20,20))
N = boxes.shape[0] # number of instances
colors = random_colors(N)
# Show area outside image boundaries.
height, width = image.shape[:2]
ax.set_ylim(height+10, -10)
ax.set_xlim(-10, width+10)
ax.axis('off')
masked_image = image.astype(np.uint32).copy()
for i in range(N):
color = colors[i]
# Bounding box
if not np.any(boxes[i]):
# Skip this instance. Has no bbox. Likely lost in image cropping.
continue
y1, x1, y2, x2 = boxes[i]
p = patches.Rectangle((x1, y1), x2-x1, y2-y1, linewidth=2, alpha=0.7, linestyle="dashed",
edgecolor=color, facecolor='none')
ax.add_patch(p)
# Label
class_id = class_ids[i]
score = scores[i] if scores is not None else None
label = class_names[class_id]
x = random.randint(x1, (x1+x2)//2)
ax.text(x1, y1+8, "{} {:.3f}".format(label, score) if score else label,
color='w', size=11, backgroundcolor="none")
# Mask
mask = masks[:,:,i]
masked_image = apply_mask(masked_image, mask, color)
# Mask Polygon
# Pad the mask to ensure proper polygons for mask that touch image edges.
padded_mask = np.zeros((mask.shape[0]+2, mask.shape[1]+2), dtype=np.uint8)
padded_mask[1:-1,1:-1] = mask
contours = find_contours(padded_mask, 0.5)
for verts in contours:
# Subtract the padding and flip (y, x) to (x, y)
verts = np.fliplr(verts) - 1
p = Polygon(verts, facecolor="none", edgecolor=color)
ax.add_patch(p)
return plt.imshow(masked_image.astype(np.uint8))
def display_top_masks(image, mask, class_ids, class_names, limit=4):
"""Display the given image and the top few class masks."""
to_display = []
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册