What your tensor dimensions stand for? I presume that 2nd and 3rd is width and height? Have you read the docs 92 about toPILImage? There is everything you need to know.
You have to have your tensor (as error message states) in 2 (H x W) or 3 (C x H x W) dimensions. 2 If the image is greyscale, ad 3 if the image is in color. The additional dimension (that probably stands for batch size?) has to be removed, i.e. you can transform the tensor in a loop.