IniziaInizia gratis

Setup up semantic masks

A common way to perform panoptic segmentation is to combine together the outputs of semantic and instance segmentation. Consider the following image of a New York street.

street image

Your task is to segment it panoptically, such that each cab is identified as a separate object, while distinguishing between the asphalt and building backgrounds.

To achieve it, you will start by producing a semantic mask with a pre-trained U-Net, available to you as UNet(). Hopefully, it should distinguish between the two background types (but not between particular cabs)!

Questo esercizio fa parte del corso

Deep Learning for Images with PyTorch

Visualizza il corso

Istruzioni dell'esercizio

  • Instantiate the U-Net model as model.
  • Generate semantic_masks by passing the input image tensor to the model.
  • Create single semantic mask by choosing the highest-probability class for each pixel.

Esercizio pratico interattivo

Prova a risolvere questo esercizio completando il codice di esempio.

# Instantiate the model
model = ____

# Produce semantic masks for the input image
with torch.no_grad():
    semantic_masks = ____

# Choose highest-probability class for each pixel
semantic_mask = ____(____, ____)

# Display the mask
plt.imshow(semantic_mask.squeeze(0))
plt.axis("off")
plt.show()
Modifica ed esegui il codice