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.
Bu egzersiz
Deep Learning for Images with PyTorch
kursunun bir parçasıdırEgzersiz talimatları
- Extract masks and labels from the
prediction, assigning them tomasksandlabels, 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.
Uygulamalı interaktif egzersiz
Bu örnek kodu tamamlayarak bu egzersizi bitirin.
# 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()