1

I want to create a confusion matrix as it is shown here, though I use a different dataset than FashinMNIST. Concretely, I want the axes to contain names such as "banana", "orange", "cucumber", etc. I have a folder where images of bananas, etc. are stored, which I load with PyTorch's ImageFolder class. Now, PyTorch automatically assings the numbers 0 to 9 to my classes (I have 10 classes in total), but I'm not sure whether the label "banana" always gets the same number 0.

How do I find out, when using the ImageFolder class, which index belongs to which label (subfolder name)?

desertnaut
  • 57,590
  • 26
  • 140
  • 166
Hermi
  • 350
  • 2
  • 5
  • 16

1 Answers1

3

Class ImageFolder has attribute class_to_idx. Check the docs.

x = torchvision.datasets.ImageFolder(root=path, transform=transform)
print(x.class_to_idx)
Dharman
  • 30,962
  • 25
  • 85
  • 135
Trong Van
  • 374
  • 1
  • 13