im facing the problem ‘pic should be tensor or ndarray’ .  i check both img and to pil image on transforms. how to fix this problem ?

Blockquote
TypeError: Caught TypeError in DataLoader worker process 0.
Original Traceback (most recent call last):
File “/usr/local/lib/python3.6/dist-packages/torch/utils/data/_utils/worker.py”, line 185, in _worker_loop
data = fetcher.fetch(index)
File “/usr/local/lib/python3.6/dist-packages/torch/utils/data/_utils/fetch.py”, line 44, in fetch
data = [self.dataset[idx] for idx in possibly_batched_index]
File “/usr/local/lib/python3.6/dist-packages/torch/utils/data/_utils/fetch.py”, line 44, in 
data = [self.dataset[idx] for idx in possibly_batched_index]
File “”, line 40, in getitem
self.sample = self.transform(self.sample)
File “/usr/local/lib/python3.6/dist-packages/torchvision/transforms/transforms.py”, line 61, in call
img = t(img)
File “/usr/local/lib/python3.6/dist-packages/torchvision/transforms/transforms.py”, line 172, in call
return F.to_pil_image(pic, self.mode)
File “/usr/local/lib/python3.6/dist-packages/torchvision/transforms/functional.py”, line 190, in to_pil_image
raise TypeError(‘pic should be Tensor or ndarray. Got {}.’.format(type(pic)))
TypeError: pic should be Tensor or ndarray. Got <class ‘dict’>.

train_transform = transforms.Compose([transforms.ToPILImage(),                                  
  transforms.Resize(226),
  transforms.RandomVerticalFlip(p=0.5),
transforms.ToTensor(), 
  
])


class DatasetLoader_Custom(Dataset):
    def __init__(self,root_dir, transform=None):
        """
        Args:
            root_dir (string): Directory with all the images.
            transform (callable, optional): Optional transform to be applied
                on a sample.
        """
        self.images = []
        self.label = []
        for filename in os.listdir(root_dir):
          for folder in os.listdir(os.path.join(root_dir,filename)):
            img = Image.open(os.path.join(os.path.join(root_dir,filename),folder))
            text = filename
            if img is not None:
              #zeros = np.zeros(3,960,720)
              img = np.array(img)
              img = img.transpose(2,1,0)
              if text.find("_") > 0:
                self.images.append(img)
              else:
                self.label.append(img)
            else:
              print('Errorrr')

        self.transform = transform
        
        print("Images: ",self.images[1])
        print(self.images[1].shape)
        print("************************")
        print("Label: ",self.label[1])
        print(self.label[1].shape)
    def __len__(self):
        return len(self.images)

    def __getitem__(self, x):
        self.sample = {'image': self.images, 'landmarks': self.label}

        if self.transform:
            self.sample = self.transform(self.sample)
        self.images = self.sample['image']
        self.labels = self.sample['landmarks']

        return self.images[x],self.labels[x]