You’re getting the error because you’re using the transform ToPILImage on a tensor that just cannot form a PIL Image. PIL images have a maximum channel dimension of 4 that they can work with, whereas you have 143 channels.
You can see how your error arises if you check out the source code for ToPILImage here:
https://pytorch.org/vision/stable/_modules/torchvision/transforms/functional.html#to_pil_image 1