Advertisement
Guest User

Untitled

a guest
Apr 21st, 2018
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.86 KB | None | 0 0
  1. class DatasetPerson(Dataset):
  2.     """Dataset containing images from only one person without face detection"""
  3.  
  4.     def __init__(self, root_dir, transform=None):
  5.         """
  6.        :param root_dir: Directory with the images.
  7.        :param transform: Transformations applied to the images.
  8.        """
  9.         self.transform = transform
  10.         self.root_dir = root_dir
  11.         self.file_names = os.listdir(self.root_dir)
  12.         self.images = []
  13.  
  14.         # load all images into ram
  15.         for img_name in self.file_names:
  16.             path2img = os.path.join(self.root_dir, img_name)
  17.             img = cv2.imread(path2img)
  18.             if self.transform:
  19.                 img = self.transform(img)
  20.             self.images.append(img)
  21.  
  22.     def __len__(self):
  23.         return len(self.images)
  24.  
  25.     def __getitem__(self, idx):
  26.         return self.images[idx]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement