text: import os.path
  from glob import glob
  
  from torch.utils import Dataset
  
  from PIL import Image
  
  class DatasetFolder(Dataset):
      def __init__(self, root, pattern, transform=None, target_transform=None):
          # classes, class_to_idx = find_classes(root)
          samples = glob(pattern)
  
          self.loader = loader
          self.samples = samples
  
          self.transform = transform
          self.target_transform = target_transform
  
      def __getitem__(self, index):
          """
          Args:
              index (int): Index
  
          Returns:
              tuple: (sample, target) where target is class_index of the target class.
          """
          path, target = self.samples[index]
          sample = self.loader(path)
          if self.transform is not None:
              sample = self.transform(sample)
          if self.target_transform is not None:
              target = self.target_transform(target)
  
          return sample, target
  
      def __len__(self):
          return len(self.samples)
  
  
  def pil_loader(path):
      # open path as file to avoid ResourceWarning (https://github.com/python-pillow/Pillow/issues/835)
      with open(path, 'rb') as f:
          img = Image.open(f)
          return img.convert('RGB')
  