1. Learn
  2. /
  3. Courses
  4. /
  5. Deep Learning for Images with PyTorch

Connected

Exercise

Segmenting image with a mask

With the binary mask ready, you can use it to segment the object, that is the cat, out of the image.

To do so, you will need to load the original image and transform it to a tensor. Next, you will create the object tensor by masking the original image. Finally, you will display the result.

transforms from torchvision have been imported, and the binary_mask you created in the previous exercise is available to you.

Instructions

100 XP
  • Create image_tensor by applying the ToTensor() transform, defined as transform, to the raw image.
  • Segment the image by masking the image_tensor with the binary_mask, assigning the result to object_tensor.
  • Apply the already defined to_pil_image transform to the object_tensor in order to display it.