Could you try to reduce the batch size and rerun the code again?
Your current transformation will most likely not work for these issues:


transforms.ToPILImage() does not have a convert method, which is a method of PIL.Image

Transformations for PIL.Images work on single images, so you would need to loop your input tensor as:

x = torch.randn(2, 3, 224, 224)
out = []
for x_ in x:
    out.append(transform(x_))
out = torch.stack(out)