Keras在使用ImageDataGenerator时产生错误



我正在尝试做一个简单的任务,其中模型将图像作为输入并产生另一个图像作为输出。有两个名为input的文件夹,其中包含输入图像,另一个名为output的文件夹包含ground truth图像或y标签。为了在训练和验证中分割整个文件夹,我执行了以下步骤:

# This is supposed to make training split which contains x label
train_set_X = train_datagen.flow_from_directory(
train_path,
class_mode='input',
classes=['input'],
subset='training'
)
# This is supposed to make validation split which contains x label
validation_set_X = train_datagen.flow_from_directory(
train_path,
class_mode='input',
classes=['input'],
subset ='validation'
)

# THis makes the training split's Y label
train_set_Y = train_datagen.flow_from_directory(
train_cleaned_path,
class_mode='input',
classes=['output'],
subset ='training'
)
# THis makes the validation split's Y label
validation_set_Y =train_datagen.flow_from_directory(
train_cleaned_path,
class_mode='output',
classes=['train_cleaned'],
subset ='validation'
)

但是当我使用上面提到的分割时,如下所示:

history= conv_NN.fit(train_set_X, train_set_Y,
validation_data = (validation_set_X, validation_set_Y), 
epochs=20, batch_size=16,
callbacks= [early_stop,tensorboard_callback], 
verbose=1)

我得到以下错误:

ValueError: `y` argument is not supported when using `keras.utils.Sequence` as input.

请帮助我知道这里发生了什么,我做错了什么?提前谢谢。

使用生成器模型时。Fit期望生成器同时提供x和y值。因此,您不能像使用代码

那样指定y标签
history= conv_NN.fit(train_set_X, train_set_Y

我认为你可以实现你想要的

train_gen=zip(train_set_X,train_set_Y)
valid_gen=zip(validation_set_X,validation_set_Y)
history= conv_NN.fit(train_gen,valisation_data = valid_gen,  
epochs=20, batch_size=16,
callbacks= [early_stop,tensorboard_callback], 
verbose=1)

相关内容

  • 没有找到相关文章

最新更新