OK,
It seems your image and masks are CV2 objects. Pytorch’s image backend is Pillow if you want to do some transformation on it. And as you can see in ToTensor class, it expects numpy array or PIL image. So you can solve this issue by converting your image and masks to numpy or Pillow image in __getitem()__.
I have not tried it by np.array(your image or mask) should do the job.