Both methods have the same effect.



 Cverlpeng:

TF.to_tensor(mask) this might destroy the labels ?


Yes, depending on the format of your target image.
E.g. if your target image is a color image where each different color encodes a class, you should rather create a mapping between colors and classes. ToTensor will normalize the image such that the values will be in [0, 1] which won’t be suitable to use in e.g. nn.CrossEntropyLoss anymore, as it expects class indices in the range [0, nb_classes].