Skip to content

Instantly share code, notes, and snippets.

@peter0749
Created January 6, 2020 08:59
Show Gist options
  • Save peter0749/8e806803ddd3c6bec9515845f32df553 to your computer and use it in GitHub Desktop.
Save peter0749/8e806803ddd3c6bec9515845f32df553 to your computer and use it in GitHub Desktop.
class ImageFolderEX(datasets.ImageFolder):
def __getitem__(self, index):
while True:
path, label = self.imgs[index]
try:
img = self.loader(os.path.join(self.root, path))
if self.transform is not None:
img = self.transform(img)
except:
index = np.random.randint(self.__len__())
continue
break
return [img, label]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment