Ah sorry, ToPILImage is of course not needed, if you already provide the input as a PIL.Image.
I just copied your transformation without checking it. Just remove transforms.ToPILImage() and rerun the code.