Reputation: 153
I have a doubt regarding the following tutorial https://blog.keras.io/building-powerful-image-classification-models-using-very-little-data.html
Here we are taught how to make CNN on very less data. It's told the Data is divided in training and Validation folders having images of Cats and Dogs
I'm not able to understand the how Image generator understands the Labels. Here is the Code Block of Image Generator from the Tutorial
# this is the augmentation configuration we will use for training
train_datagen = ImageDataGenerator(
rescale=1./255,
shear_range=0.2,
zoom_range=0.2,
horizontal_flip=True)
# this is the augmentation configuration we will use for testing:
# only rescaling
test_datagen = ImageDataGenerator(rescale=1./255)
# this is a generator that will read pictures found in
# subfolers of 'data/train', and indefinitely generate
# batches of augmented image data
train_generator = train_datagen.flow_from_directory(
'data/train', # this is the target directory
target_size=(150, 150), # all images will be resized to 150x150
batch_size=batch_size,
class_mode='binary') # since we use binary_crossentropy loss, we need binary labels
# this is a similar generator, for validation data
validation_generator = test_datagen.flow_from_directory(
'data/validation',
target_size=(150, 150),
batch_size=batch_size,
class_mode='binary')
The Train folder Contains mixed images of cats and dogs. I'm failing to understand how it understand the labels for each image.
train_generator = train_datagen.flow_from_directory(
'data/train', # this is the target directory?????
target_size=(150, 150), # all images will be resized to 150x150
batch_size=batch_size,
class_mode='binary') # since we use binary_crossentropy loss, we need binary labels
How does data/train know the corresponding labels. Kindly Guide me Your's Sincerely, Vidit Shah
Upvotes: 0
Views: 142
Reputation: 86600
The train folder does not contain "mixed" images. It contains images separated in subfolders.
For ImageDataGenerator
, each subfolder is a class.
From the link you gave:
a training data directory and validation data directory containing one subdirectory per image class, filled with .png or .jpg images:
Upvotes: 3