In the docs 20 it says that you can give a mode to the ToPILImage(). Try ToPILImage('RGB')
If that doesn’t work. Can you print the size() of your tensor before you transform it to a PIL image?
Could you also print the mode of your input image. In the for loop before the transform do a print(ak)