Created
September 4, 2021 18:56
-
-
Save martinetmayank/563c5b055a7567d393ffb62b73b91d7b to your computer and use it in GitHub Desktop.
Using ImageDataGenerator to read images form the directories
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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