I want to make a user friendly GUI image classifier where the user would just need to point to the directory of the data set to get the model trained and then they can give any image to the program and it will display the probability and label of the object in the image. But how do I get the names of the classes scanned by .flow_from_directory function of ImageDataGenerator in Keras?
From the documentation, "The dictionary containing the mapping from class names to class indices can be obtained via the attribute class_indices
."
https://keras.io/preprocessing/image/#flow_from_directory
In the example below, the train_data_dir
contains two sub-folders, cat
and dog
.
train_datagen = ImageDataGenerator(rescale=1. / 255)
train_generator = train_datagen.flow_from_directory(
train_data_dir,
target_size=(img_width, img_height),
color_mode='grayscale',
shuffle = True,
batch_size=batch_size,
class_mode='binary')
print(train_generator.class_indices)
{'cat': 0, 'dog': 1}
`
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With