how to do train test split in keras imagedatagenerator

Solutions on MaxInterview for how to do train test split in keras imagedatagenerator by the best coders in the world

showing results for - "how to do train test split in keras imagedatagenerator"
Nolann
28 Sep 2017
1train_datagen = ImageDataGenerator(rescale=1./255,
2    shear_range=0.2,
3    zoom_range=0.2,
4    horizontal_flip=True,
5    validation_split=0.2) # set validation split
6
7train_generator = train_datagen.flow_from_directory(
8    train_data_dir,
9    target_size=(img_height, img_width),
10    batch_size=batch_size,
11    class_mode='binary',
12    subset='training') # set as training data
13
14validation_generator = train_datagen.flow_from_directory(
15    train_data_dir, # same directory as training data
16    target_size=(img_height, img_width),
17    batch_size=batch_size,
18    class_mode='binary',
19    subset='validation') # set as validation data
20
21model.fit_generator(
22    train_generator,
23    steps_per_epoch = train_generator.samples // batch_size,
24    validation_data = validation_generator, 
25    validation_steps = validation_generator.samples // batch_size,
26    epochs = nb_epochs)
27