I am trying to customize
ImageFolder to return the image, category and sub-category names. Yet, here’s what worked for my case:
def __getitem__(self, index):
return super(ImageFolder, self).__getitem__(index), self.imgs[index]
Are there any better ways?
This looks like a quick and valid approach. You could of course derive a custom class from
ImageFolder, but if you don’t need any other changes, I would probably just use yours.
It worked pretty well, as I passed a loader that read the images according to my needs, and a custom transform that plays with the images the way I want. Needless to say that
DatasetFolder is also a very nice option/alternative as one can pass the extensions of the files to load.