Image data augmentation by using ImageDataGenerator
Mon Apr 18 2022 05:19:13 GMT+0000 (Coordinated Universal Time)
Saved by
@hasitha
#python
#direcotry
#folder
#file
#creator
train_datagen = image.ImageDataGenerator(
rescale = 1./255, # to normalize bigger values. Convert from 0-255 to 0-1 range.
shear_range = 0.2,
zoom_range = 0.2,
horizontal_flip = True
)
# only rescaling done on test dataset
test_datagen = image.ImageDataGenerator(
rescale = 1./255
)
train_generator = train_datagen.flow_from_directory(
directory=TRAIN_PATH,
target_size=(224,224),
batch_size=32,
class_mode='binary',
save_to_dir = SAVE_TRAIN_PATH,
save_prefix='',
save_format='png'
)
validation_generator = test_datagen.flow_from_directory(
VAL_PATH,
target_size = (224,224),
batch_size = 32,
class_mode = 'binary'
)
#
train_generator.class_indices
validation_generator.class_indices
# generate augmented images and save into the directory
for i in range(5):
train_generator.next()
content_copyCOPY
Generate batches of tensor image data with real-time data augmentation.
tf.keras.preprocessing.image.ImageDataGenerator
https://www.tensorflow.org/api_docs/python/tf/keras/preprocessing/image/ImageDataGenerator
Comments