Is there a way to return the image file names when iterating over images through DataLoaders.
Just return {'image': img, 'filename': filename}
in __getiter__
of your dataset.
Batching with DataLoader
should work as expected.
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
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
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.
Here’s the same question posted in another thread, with suggested solution: DataLoader Filenames in each Batch