Usage of imagefloder in pytorch

The key to the problem is how to determine the correspondence between pictures and categories

from torchvision.datasets import ImageFolder

dataset = ImageFolder('F:/my_code/data/0dB/train/')

Read in data

print(dataset.imgs[2])

At this point, dataset.imgs is a list with many elements, and the second one
is selected and the output is

('F:/my_code/data/0dB/train/BFSK\\BFSK100.jpg', 0)

That is to say, the imagefolder should be arranged in the order of the folder name,
BFSK corresponds to 0,
BPSK corresponds to 1,
etc...

Guess you like

Origin blog.csdn.net/huatianxue/article/details/110849488