Aan de slagGa gratis aan de slag

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.

Deze oefening maakt deel uit van de cursus

Deep Learning for Images with PyTorch

Cursus bekijken

Oefeninstructies

  • Extract masks and labels from the prediction, assigning them to masks and labels, respectively.
  • Inside the for-loop, display the i-th mask over the image by passing mask[i, 0] to the plotting function, using the "jet" color map and setting the transparency parameter to 0.5.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# 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()
Code bewerken en uitvoeren