I have a set of images in a directory train_data = 'dataset/train'
for handwritten Arabic letters, but it only contains the images in one folder and is not divided into subfolders in order for the ImageDataGenerator().flow_from_directory(train_data, class_mode='categorical', batch_size=64
function to understand the classes we want to classify.
When I first used Keras for CNN the images were divided in the training directory like this: dataset/training_set/cats
and dataset/training_set/dogs
and the same applies to the testing set directory, The output of ImageDataGenerator().flow_from_directory()
gave me this line: Found 8000 images belonging to 2 classes.
This is how the images in the folder are named:
-
id_1_label_1.png
-
id_2_label_2.png
And here is a picture so it is clearer: enter image description here Train data in my directory
The labels are part of the file name as shown above.
I tried running the following code to read the images:
train_datagen = ImageDataGenerator(rescale = 1./255,
shear_range = 0.2,
zoom_range = 0.2,
horizontal_flip = True)
training_set = train_datagen.flow_from_directory('dataset/train',
target_size = (64, 64),
batch_size = 32,
class_mode = 'categorical')
But it gave me this output: Found 0 images belonging to 0 classes.
How can I load the data using Keras for CNN in order for ImageDataGenerator
to understand how many classes we have?
David Magdy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.