Okay, so now we know that the MyDataset class is ok.
But now, why do you have this other transform() function? So have you removed the transformations in __getitem__, and instead you call his function inside __getitem__?
Also, youshouldn’t have to read the masks in RGB. You can directly read them as Grayscale.