The error is most likely thrown because your mask is still a PIL.Image instead of a tensor.
I guess using transforms.ToTensor() wouldn’t be the best idea in this case, as you are dealing with a semantic segmentation task, i.e. your mask should contain class indices for all pixels.
Does you current mask hold a specific color code so that we could use it to create a mask tensor with class indices?