ToPILImage() will not reconstruct the original image, if you’ve normalized it as seen here:
img = transforms.ToPILImage()(torch.randn(3, 224, 224))

norm = transforms.Compose([
        transforms.ToTensor(),
        transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225]) # comment this line
])


x_norm = norm(img)
img_reconstructed = transforms.ToPILImage()(x_norm)
print((np.array(img_reconstructed) == np.array(img)).all())
> False

If you comment out the mentioned line it’ll work.
Alternatively, you could also “unnormalize” the image, but this would most likely yield small rounding errors, so that some pixel in the uint8 format might be off by 1:
x_norm = norm(img)
x = x_norm * torch.tensor([0.229, 0.224, 0.225])[:, None, None] + torch.tensor([0.485, 0.456, 0.406])[:, None, None]

img_reconstructed = transforms.ToPILImage()(x)
print((np.array(img_reconstructed).astype(np.long) - np.array(img).astype(np.long)))