Exercise: Download a Pretrained Semantic Segmentation CNN

Apply your knowledge to download a pretrained semantic segmentation CNN, and test it with images of natural scenes.

Problem statement

In this exercise, download a pretrained CNN for semantic segmentation. You’ll test the CNN performance with some images of natural scenes and create annotation images showing the found objects.

Launch the Jupyter Notebook below and follow the instructions.

Instructions:

  • The comment lines starting with # >>> indicate that you must edit the cell.

  • Replace the None values with the correct function calls.

The main steps that you’ll have to complete are:

  1. Load the pretrained weights of a DeepLabV3 CNN with a MobileNetV3 backbone.

  2. Extract the transformation pipeline and the list of categories from the weights object.

  3. For each image URL in a list:

    1. Load a PIL image.

    2. Create a batch tensor.

    3. Pass the batch tensor through the CNN.

    4. Extract, for each pixel, the index of the highest logit value.

    5. Convert the index to color in a semantic segmentation image.

    6. Resize the semantic segmentation image to the original size.

Expected output

If everything works like clockwork, you should obtain a pair of images showing the original image and their corresponding semantic segmentation:

Get hands-on with 1400+ tech skills courses.