ptrblck:

WeightedRandomSampler


So currently I am using custom dataset and the class looks like this:
class CustomData(Dataset):
    """
    CustomData dataset
    """

    def __init__(self, name, dirpath, transform=None, should_invert=False):
        super(Dataset, self).__init__()
        self.dirpath = dirpath
        self.imageFolderDataset = dset.ImageFolder(root=self.dirpath)
        self.transform = transform
        self.should_invert = should_invert
        self.to_tensor = transforms.ToTensor()

    def __getitem__(self, index):
        # Training images
        images = self.imageFolderDataset.imgs
        img = cv2.imread(images[index][0])

        if self.should_invert:
            img = PIL.ImageOps.invert(img)

        if self.transform is not None:
            img = self.transform(img)

        img = np.array(img, dtype='uint8')
        img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
        img_as_tensor = self.to_tensor(img)
        return img_as_tensor, images[index][1]

    def __len__(self):
        return len(self.imageFolderDataset.imgs)

How can I incorporate reading from particular folder because ImageFolder gives error if there is no directory inside?