-2

I have separated my entire data into various folders for different classes for hand digit recognition. How do I let my model know that a certain class A contains images depicting the letter A.

Academic
  • 281
  • 3
  • 12
soldour
  • 11
  • 4

1 Answers1

1
train_datagen = ImageDataGenerator(
    rescale=1.0 / 255, shear_range=0.2, zoom_range=0.2, horizontal_flip=True
)
train_generator = train_datagen.flow_from_directory(
        "Image Folder/", target_size=(28, 28), batch_size=1, class_mode="binary"
    )
print(train_generator[0])

In the example above Image folder must have sub-folders for each class like below:

  • some/path/
    • class1/
      • image1.jpg
      • image2.jpg
    • class2/
      • image3.jpg
      • etc
    • etc
  • thank you very much! so the class name should have the same name with that of the character it is representing right? for example, if the folder contains latter A the folder name should be " A" right? – soldour Aug 31 '20 at 10:48
  • @soldour Keras assumes that images are stored in a folder tree with one separate subfolder per class. So you have to name the folder as well as the class name. –  Aug 31 '20 at 17:12