flow from directory validation split code example
Example 1: split imagedatagenerator into x_train and y_train
in python 2:
X_train, y_train = train_generator.next()
X_test, y_test = validation_generator.next()
in python 3:
X_train, y_train = next(train_generator)
X_test, y_test = next(validation_generator)
Example 2: how to split image dataset into training and test set keras
train_datagen = ImageDataGenerator(rescale=1./255,
shear_range=0.2,
zoom_range=0.2,
horizontal_flip=True,
validation_split=0.2)
train_generator = train_datagen.flow_from_directory(
train_data_dir,
target_size=(img_height, img_width),
batch_size=batch_size,
class_mode='binary',
subset='training')
validation_generator = train_datagen.flow_from_directory(
train_data_dir,
target_size=(img_height, img_width),
batch_size=batch_size,
class_mode='binary',
subset='validation')