Displaying soft masks
In the previous exercise, you have learned that the top two most likely objects the Mask R-CNN model has segmented are both cats. Now, you will display the masks for these two cats overlaid on top of the original image to visually verify their accuracy. This will require iterating over the two masks, and for each of them, plotting the original image followed by a semi-transparent mask on top of it.
This exercise is part of the course
Deep Learning for Images with PyTorch
Exercise instructions
- Extract masks and labels from the
prediction
, assigning them tomasks
andlabels
, respectively. - Inside the for-loop, display the
i
-th mask over the image by passingmask[i, 0]
to the plotting function, using the"jet"
color map and setting the transparency parameter to0.5
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Extract masks and labels from prediction
masks = ____
labels = ____
# Plot image with two overlaid masks
for i in range(2):
plt.imshow(image)
# Overlay the i-th mask on top of the image
plt.imshow(____, ____, ____)
plt.title(f"Object: {class_names[labels[i]]}")
plt.show()