1
votes

I am trying to do K-fold cross validation on Keras model (with ImageDataGenerator and flow_from_directory for training and validation data), I want to know if the argument "validation_split" in "ImageDataGenerator"

    test_datagen = ImageDataGenerator(
    rescale=1. / 255,
    rotation_range = 180,
    width_shift_range = 0.2,
    height_shift_range = 0.2,
    brightness_range = (0.8, 1.2),
    shear_range = 0.2,
    zoom_range = 0.2,
    horizontal_flip = True,
    vertical_flip = True,
    validation_split = 0.1

)

train_datagen = ImageDataGenerator(
    rotation_range = 180,
    width_shift_range = 0.2,
    height_shift_range = 0.2,
    brightness_range = (0.8, 1.2),
    rescale = 1. / 255,
    shear_range = 0.2,
    zoom_range = 0.2,
    horizontal_flip = True,
    vertical_flip = True,
    validation_split = 0.1
)

train_generator = train_datagen.flow_from_directory(
    train_data_dir,
    target_size = (img_width, img_height),
    batch_size = batch_size,
    class_mode ='binary',
    seed = 42
)

validation_generator = test_datagen.flow_from_directory(
    validation_data_dir,
    target_size = (img_width, img_height),
    batch_size = batch_size,
    class_mode = 'binary',
    seed = 42
)

history = model.fit_generator(
    train_generator,
    steps_per_epoch = nb_train_samples // batch_size,
    epochs = epochs,
    validation_data = validation_generator,
    validation_steps = nb_validation_samples // batch_size)

Is the "validation_split = 0.1" means that I've already done 10-fold cross validation on my dataset?

1

1 Answers

4
votes

No. It only does the validation once. From the official document:

validation_split: Float between 0 and 1. Fraction of the training data to be used as validation data. The model will set apart this fraction of the training data, will not train on it, and will evaluate the loss and any model metrics on this data at the end of each epoch. The validation data is selected from the last samples in the x and y data provided, before shuffling.

Thus setting it as validation_split=0.1 simply keeps last 10% of your data from training, and use it as a validation set.

If you want to do the k-cross validation, you must do so manually. Here's a good starting point: Evaluate the Performance of Deep Learning Models in Keras