This code produces the output <PIL.Image.Image image mode=RGB size=128x128 at 0x11A40AEF0>. I’m guessing it has to do with the input data being in a non-standard way. What dataset are you working with?
from PIL import Image
import torch
from torchvision import transforms

transform=transforms.Compose([
  transforms.CenterCrop((128,128)),
  transforms.ToTensor(),
 ])

images=torch.zeros(2,3,128,128)
for i in range(2):
    ak=Image.open('testimage.jpg') # Mode=RGB=3 channels
    ak=transform(ak) 
    images[i]=ak


to_pil = transforms.ToPILImage()
tar = to_pil(images[0])
print(tar)


Edit: I tried the image you uploaded and it isn’t a normal RGB image. Says <PIL.PngImagePlugin.PngImageFile image mode=P size=500x281 at 0x11231B1D0>. You can read at the different modes at the docs 23