In that case you could map each mask to a class index assuming that the targets do not overlap and you are thus working on a multi-class segmentation use case as seen here:
# Create non-overlapping masks
mask1 = torch.zeros(1, 24, 24).long()
mask1[:, :2, :2] = 1

mask2 = torch.zeros(1, 24, 24).long()
mask2[:, 3:6, 3:6] = 1

mask3 = torch.zeros(1, 24, 24).long()
mask3[:, 15:18, 15:18] = 1

# map masks to class indices
mask2[mask2==1] = 2
mask3[mask3==1] = 3

# create target mask
mask = mask1 + mask2 + mask3

plt.imshow(mask.squeeze(0))
print(mask.unique())
> tensor([0, 1, 2, 3])