简体   繁体   中英

keras datagen.flow_from_directory class mode categorical get labels wrong

I have training dataset of images for 24 class each class has 2800 image the classes are separated one from each other in directory all in one directory called training

i used the following code to load the data using keras:

datagen = ImageDataGenerator(rescale= 1./255
                             ,fill_mode='nearest')

train_data = datagen.flow_from_directory('training-images',class_mode='categorical',
                                         target_size=(32,32))

it load the images but the images get the wrong label

the directory structure as follows:

training-images/
  0/
     image.jpg
     .
     .
  1/
     image.jpg
     .
     .
  .
  .
  23/
     image.jpg
     .
     .

flow_from_directory orders the classes alphabetically, not numerically. This means that your classes will be ordered 0, 1, 11, 12, 13, 14, 15, 16, 17, 18, 19, 2, 20, 21, 22, 23, 24, 3, 4, 5, 6, 7, 8, 9. If I were you, I would give the folders descriptive names (eg for CIFAR10, they would be "airplane", "bird", etc.), and then map the generated IDs to the class names using .class_indices .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM