Return image names/path when iterating through DataLoader


(Devansh Bisla) #1

Is there a way to return the image file names when iterating over images through DataLoaders.


(Sasank Chilamkurthy) #2

Just return {'image': img, 'filename': filename} in __getiter__ of your dataset.
Batching with DataLoader should work as expected.


(Devansh Bisla) #3

Thanks I’m still having trouble trying to figure it out. I’m loading my dataset through Imagefolder and iteratin through DataLoader. I added the filename in getitem of Imagefolder but iterating still gives me only target and label


(Devansh Bisla) #4

class MyImageFolder(datasets.ImageFolder):
def getitem(self, index):
return super(MyImageFolder, self).getitem(index), self.imgs[index]#return image path

This works but I was just hoping to edit the Imagefolder files


(Sasank Chilamkurthy) #5

I was suggesting you create your own dataset. You can see an example of creating dataset: http://pytorch.org/tutorials/beginner/data_loading_tutorial.htm

But your approach is cool too.