gpt4 book ai didi

python - 在 Keras "ImageDataGenerator"中, "validation_split"参数是一种 K 折交叉验证吗?

转载 作者:行者123 更新时间:2023-12-02 03:16:34 24 4
gpt4 key购买 nike

我正在尝试对 Keras 模型进行 K 折交叉验证(使用 ImageDataGenerator 和 flow_from_directory 用于训练和验证数据),我想知道“ImageDataGenerator”中的参数“validation_split”是否有效

    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 倍交叉验证?

最佳答案

没有。它只进行一次验证。来自 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.

因此将其设置为 validation_split=0.1 只是保留最后 10% 的训练数据,并将其用作验证集。

如果您想进行 k 交叉验证,则必须手动进行。这是一个很好的起点:Evaluate the Performance of Deep Learning Models in Keras

关于python - 在 Keras "ImageDataGenerator"中, "validation_split"参数是一种 K 折交叉验证吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55963087/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com