Unexpected ouput of torchvision.transforms

input and output image shown as following
input
output

and my test code is

train_transform = transforms.Compose([
     transforms.RandomResizedCrop(224),
     transforms.RandomHorizontalFlip(),
     transforms.ToTensor(),
    ])
 a = SceneData(os.getcwd(), split='train',transform=train_transform)
 img, label = a[0]
 img = img.numpy().transpose(1,2,0)
 img = Image.fromarray(img, 'RGB')
 img.show()

the __getitem__() in dataset.py is

def __getitem__(self, index):
    file_id, category_id = self.all_data[index]
    img_path = osp.join(self.image_dir, self.split, file_id+'.jpg')
    
    try:
      img = Image.open(img_path)
    except Exception as e:
      raise e

    lbl = int(category_id)
    
    if img.mode == 'RGB':
      if self.transform:
        img = self.transform(img)
      return img, lbl

Anyone got the point to sovle it?

img = img.transpose((1, 2, 0))

changes original form of PIL image, so img.show() don’t make sense if you want to check the cropped image.

I guess you can check cropped image as follow:

train_transform = transforms.Compose([
     transforms.RandomResizedCrop(224),
     transforms.RandomHorizontalFlip(),
     transforms.ToTensor(),
    ])
 a = SceneData(os.getcwd(), split='train',transform=train_transform)
 img, label = a[0]
 img2 = img
 img = img.numpy().transpose(1,2,0)
 img = Image.fromarray(img, 'RGB')
 img2 = Image.fromarray(img, 'RGB')
 img2.show()

sorry, I didn’t get the point. if img2=img, the the type of img2 is a tensor, which means img2 has no method of show()

I modified the code above. Does it work?