I want to build a custom dataloader which will use the class name and the image name as a permanent index. How can I get the filename and folder name of the current image in __getitem__()
?
class MyDataset(Dataset):
def __init__(self, root):
.......
self.root = root
self.dataset = datasets.ImageFolder(root=self.root,
transform=transforms)
def __getitem__(self, index):
data, target = self.dataset[index]
index = index
return data, target, index
def __len__(self):
return len(self.dataset)
My Dataset directory structure is as follows:
E.g For cat image 0 → index = cat0
I would appreciate if there is any technique to extract the parent folder and file name of the current index in__getitem__(self, index)
.
Thank you.