Can flow_from_directory get train and validation data from the same directory in Keras?
You can pass validation_split
argument (a number between 0 and 1) to ImageDataGenerator
class instance to split the data into train and validation sets:
generator = ImagaDataGenerator(..., validation_split=0.3)
And then pass subset
argument to flow_from_directory
to specify training and validation generators:
train_gen = generator.flow_from_directory(dir_path, ..., subset='training')
val_gen = generator.flow_from_directory(dir_path, ..., subset='validation')
Note: If you have set augmentation parameters for the ImageDataGenerator
, then by using this solution both training and validation images will be augmented.