Skip to content

wrong label order when reading images from folders using 'ImageFolder' and can't get correct labels #714

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
zyl200846 opened this issue Jan 10, 2019 · 1 comment

Comments

@zyl200846
Copy link

When I try to load images from folders using datasets.ImagesFolder(), i find the lables' order is not correct as shown in the folder. For example, I have different kinds of images in folders named from 1 to 100, if I use above function to read images and get corresponding labels, of course I will get the images and labels, but the labels for images will become 1, 10, 100, 11, 12, 13 which is not right for corresponding image. The right order should be 1, 2, 3, 4, 5 for corresponding images.
Hope I state the problem clearly and wish you can fix this bug. Thanks.

@fmassa
Copy link
Member

fmassa commented Jan 11, 2019

The label names are sorted as strings.
This means that ['1', '10', '2'] is the correct sorting order according to Python.
You should instead use class_to_idx and classes to go back and forth between the two representations, see

self.classes = classes
self.class_to_idx = class_to_idx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants