Skip to content

Instantly share code, notes, and snippets.

@martinetmayank
Created September 4, 2021 18:56
Show Gist options
  • Save martinetmayank/563c5b055a7567d393ffb62b73b91d7b to your computer and use it in GitHub Desktop.
Save martinetmayank/563c5b055a7567d393ffb62b73b91d7b to your computer and use it in GitHub Desktop.
Using ImageDataGenerator to read images form the directories
from keras.preprocessing.image import ImageDataGenerator
# Rescaling all images by 1/255
train_datagen = ImageDataGenerator(rescale=1./255)
test_datagen = ImageDataGenerator(rescale=1./255)
train_generator = train_datagen.flow_from_directory(
directory=TRAIN_DIR,
target_size=(150, 150), # Resizing all images to 150 x 150
batch_size=20,
class_mode='binary' # Since we are using binary_crossentropy, we need binary labels.
)
validation_generator = test_datagen.flow_from_directory(
directory=VALIDATION_DIR,
target_size=(150, 150),
batch_size=20,
class_mode='binary'
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment