在Keras中,"ImageDataGenerator"是"validation_split".参数是一种K折交叉验证? [英] In Keras "ImageDataGenerator", is "validation_split" parameter a kind of K-fold cross validation?

查看:532
本文介绍了在Keras中,"ImageDataGenerator"是"validation_split".参数是一种K折交叉验证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Keras模型上进行K折交叉验证(使用ImageDataGenerator和flow_from_directory来训练和验证数据),我想知道"ImageDataGenerator"中的参数"validation_split"

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)

"validation_split = 0.1"是否意味着我已经对数据集进行了10倍交叉验证?

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

推荐答案

否.它只执行一次验证.从官方文件:

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

validation_split :在0到1之间浮动.用作验证数据的训练数据的分数.模型将分开训练数据的这一部分,不对其进行训练,并且将在每个时期结束时评估此数据的损失和任何模型度量.在进行混洗之前,从提供的x和y数据中的最后一个样本中选择验证数据.

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.

因此将其设置为validation_split=0.1只会使您的最后10%的数据免于训练,并将其用作验证集.

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

如果要进行k交叉验证,则必须手动进行. 这是一个很好的起点:评估Keras中的深度学习模型的性能

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

这篇关于在Keras中,"ImageDataGenerator"是"validation_split".参数是一种K折交叉验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆