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

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.
Bu egzersiz
Deep Learning for Images with PyTorch
kursunun bir parçasıdırEgzersiz talimatları
- Load the mask image stored in
annotations/Egyptian_Mau_123.pngand assign it tomask. - Create a
binary_maskfrommask_tensorwhere each pixel equal to1/255is assigned a tensor value of1.0, and the remaining pixels are assigned a tensor value of0.0.
Uygulamalı interaktif egzersiz
Bu örnek kodu tamamlayarak bu egzersizi bitirin.
# Load mask image
mask = ____
# Transform mask to tensor
transform = transforms.Compose([transforms.ToTensor()])
mask_tensor = transform(mask)
# Create binary mask
binary_mask = ____(
____,
____,
____,
)
# Print unique mask values
print(binary_mask.unique())