How to know which image is at what index in torchvision.datasets.ImageFolder?

Hi everyone,
i have used “trainset=datasets.ImageFolder(root=’/home/jessiepinkman/Traindata’,transform=apply_transform)” in my code to load images and convert them to tensors. Now after processing those, I get some label corresponding to each tensor. Now my problem is I need to know which index of the trainset[i], is related to which image in my dataset.

You can see the image paths and their corresponding class index using


Using the class_to_idx attribute gives the labels corresponding to each class. You can use: