Hello.
I found that for some OS system (my environment is Ubuntu20.04), the class_to_idx property of dataset.ImageFolder is not aligned with the directories' name, so it leads to wrongly label samples.
For instance, the directory 100 (str) is labelled with 2 (int) class. The easiest way to resolve the above issue is, from the dataset.ImageFolder source code (https://pytorch.org/vision/stable/_modules/torchvision/datasets/folder.html#ImageFolder), modifying the line in find_classes function class_to_idx = {cls_name: i for i, cls_name in enumerate(classes)} with class_to_idx = {cls_name: int(cls_name) for cls_name in classes}.
Hello.
I found that for some OS system (my environment is Ubuntu20.04), the
class_to_idxproperty ofdataset.ImageFolderis not aligned with the directories' name, so it leads to wrongly label samples.For instance, the directory
100 (str)is labelled with2 (int)class. The easiest way to resolve the above issue is, from thedataset.ImageFoldersource code (https://pytorch.org/vision/stable/_modules/torchvision/datasets/folder.html#ImageFolder), modifying the line infind_classesfunctionclass_to_idx = {cls_name: i for i, cls_name in enumerate(classes)}withclass_to_idx = {cls_name: int(cls_name) for cls_name in classes}.