简体   繁体   English

Keras Flow_From_Dataframe 用于回归任务

[英]Keras Flow_From_Dataframe for Regression Task

I am trying to build a CNN model to process images and solve a regression task.我正在尝试构建一个 CNN model 来处理图像并解决回归任务。 Since I have an excel that includes image paths and output values, I used flow_from_dataframe in my code.由于我有一个包含图像路径和 output 值的 excel,因此我在代码中使用flow_from_dataframe But it looks like it has no class_mode argument value for regression.但看起来它没有用于回归的class_mode参数值。 Here is my code below.下面是我的代码。 Any help is highly appreciated.非常感谢任何帮助。

kf = KFold(n_splits = n_split)

for train_ix, test_ix in kf.split(np.zeros(len(train_data)),train_data['time']):
  training_data = train_data.iloc[train_ix]
  validation_data = train_data.iloc[test_ix]
  train_data_generator = idg.flow_from_dataframe(training_data, directory = train_image_dir,
                    x_col = "id_code", y_col = "time",
                    class_mode = "raw", shuffle = True, target_size=(224, 224), batch_size = batch_size)
    
  valid_data_generator  = valid_datagen.flow_from_dataframe(validation_data, directory = valid_image_dir,
                            x_col = "id_code", y_col = "time",
                            class_mode = "raw", shuffle = False, target_size=(224, 224), batch_size = batch_size)
    
  model = compile_model()
  history = model.fit_generator(train_data_generator, validation_data=valid_data_generator, epochs=epochs, callbacks=callbacks
                                               , workers = 8, steps_per_epoch = len(train_data/batch_size))

For regression tasks, you may set the class_mode=raw to treat the data in the column or list of columns of the dataframe as raw target values.对于回归任务,您可以设置class_mode=raw以将 dataframe 的列或列列表中的数据视为原始目标值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM