'Loading test images with image-to-label mapping in PyTorch

I have a directory of jpg images I want to use for training the model and a "mapping file" with image_file_name and the corresponding label.

I am trying to create a test dataset using ImageFolder, but it requires the images to be in the subdirectories with the label name. Is there a better way for me to load the information without copying a lot of files

image_datasets = datasets.ImageFolder('/content/mydataset/train/', data_transforms['train'])

Apologies for the basic question - I am very new to PyTorch



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source