coolhand
coolhand

Reputation: 2061

Keras Image Processing of Labels

I'm following the walkthrough: https://blog.keras.io/building-powerful-image-classification-models-using-very-little-data.html

I don't understand how ImageDataGenerator creates the label data.

I have my image directories set up as: .../train/cats and .../train/dogs

My ImageDataGenerator is created by:

train_datagen = ImageDataGenerator(rescale=1./255, rotation_range=40, width_shift_range=0.2, height_shift_range=0.2, shear_range=0.2, zoom_range=0.2, horizontal_flip=True,)

train_generator = train_datagen.flow_from_directory(train_dir, target_size=(150,150), batch_size=32, class_mode='binary')

I examine the data with:

for data_batch, labels_batch in train_generator: print("labels: ", labels_batch)

The labels seem to be generated just fine. My question is, how does the ImageDataGenerator create the labels when I'm only feeding it .jpg files? I'd like to

Upvotes: 0

Views: 251

Answers (1)

Alex Taylor
Alex Taylor

Reputation: 1412

From the subdirectory names.

https://keras.io/preprocessing/image/#flow_from_directory

"classes: Optional list of class subdirectories (e.g. ['dogs', 'cats']). Default: None. If not provided, the list of classes will be automatically inferred from the subdirectory names/structure under directory, where each subdirectory will be treated as a different class (and the order of the classes, which will map to the label indices, will be alphanumeric). The dictionary containing the mapping from class names to class indices can be obtained via the attribute class_indices."

Upvotes: 1

Related Questions