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

Connected

Exercise

Creating binary masks

Images for segmentation tasks are typically annotated with pixel-level masks. Consider this image of an Egyptian Mau cat.

cat image

In this and the next exercise, you will use the corresponding mask to segment the cat out of the image. First, you will need to load the mask and binarize it.

Image from PIL, transforms from torchvision, and torch have already been imported for you.

Instructions

100 XP
  • Load the mask image stored in annotations/Egyptian_Mau_123.png and assign it to mask.
  • Create a binary_mask from mask_tensor where each pixel equal to 1/255 is assigned a tensor value of 1.0, and the remaining pixels are assigned a tensor value of 0.0.