关于mask RCNN在测试时,生成的mask是与原图片在一起的,现在想单独将mask提取出来,但是当图中有多类目标时,无法同时提取所有mask,应该是代码的for循环出了问题,但我是新手小白,不知道该如何解决,求教
def display_masks(count,image, boxes, masks, class_ids,
title="",
figsize=(6.4, 4.8), ax=None,
show_mask=True,
colors=None):
# Number of instances
N = boxes.shape[0]
if not N:
print("\n*** No instances to display *** \n")
else:
assert boxes.shape[0] == masks.shape[-1] == class_ids.shape[0]
# If no axis is passed, create one and automatically call show()
auto_show = False
if not ax:
_, ax = plt.subplots(1, figsize=figsize)
auto_show = True
# Generate random colors
colors = colors or 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')
ax.set_title(title)
masked_image = image.astype(np.uint32).copy()
for i in range(N):
color = colors[i]
# Mask
mask = masks[:, :, i]
if show_mask:
masked_image = apply_mask(masked_image, mask, color)
# Mask Polygon
# Pad to ensure proper polygons for masks 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
ax.imshow(mask.astype(np.uint8))
if auto_show:
plt.show()