【问题标题】:(Tensorflow 2.0) Keras Dataframe cannot detect the validation images(Tensorflow 2.0) Keras Dataframe 无法检测到验证图像
【发布时间】:2021-01-05 16:50:55
【问题描述】:

我尝试使用 keras.ImageDataGenerator.flow_from_dataframe,但它无法检测到验证图像,我得到了这个

找到 162770 个经过验证的图像文件名。

找到 0 个经过验证的图像文件名。

谁能帮帮我

我的代码在这里:

traindf=pd.read_csv('E:/color.csv')
columns=["Black", "White", "Red", "Blue", "Green", "Brown", "Yellow"]

datagen=ImageDataGenerator()    
train_generator=datagen.flow_from_dataframe(
dataframe=traindf,
directory="E:/Experimental_Data",
x_col="image_id",
y_col=columns,
subset="training",
batch_size=32,
seed=42,
shuffle=True,
class_mode="raw",
target_size=(178,218))

test_datagen=ImageDataGenerator()
valid_generator=test_datagen.flow_from_dataframe(
dataframe=traindf,
directory="E:/Experimental_Data",
x_col="image_id",
y_col=columns,
subset="validation",
batch_size=32,
seed=42,
shuffle=True,
class_mode="raw",
target_size=(178,218))

【问题讨论】:

  • 您是否得到 0 个经过验证的图像作为输出而不是 162770 数字所指示的值?详细说明问题。谢谢!
  • 感谢回复 数据框加载了所有为(162770)的训练图像,但无法加载验证图像并返回(0),导致模型无法计算损失函数,如图所示图片。
  • 很难找到根本原因,能否请您分享完整的代码以及示例数据来调查问题。谢谢!

标签: python-3.x tensorflow tensorflow2.0 tensorflow-datasets image-classification


【解决方案1】:

我猜这个问题的出现是因为 x_coly_col 没有相同的维度。您必须准备一个脚本,以便根据某些特征(取决于您的数据),所有 x_col 组件都有各自的 y_col 组件。您作为列表包含在 columns 中的所有颜色都必须映射到该脚本中的每个 x_col。然后您可以使用该映射来定义您的 y_colx_coly_col 的尺寸将匹配。之后其余的将正常工作。祝你好运!

【讨论】:

    【解决方案2】:

    事实证明,您必须在调用 ImageDataGenerator 时设置验证分数,例如:

    datagen=ImageDataGenerator(validation_split=0.2)
    

    我也遇到了同样的问题,现在已经解决了。 在https://keras.io/api/preprocessing/image/#flowfromdataframe-method找到答案:

    subset:如果在 ImageDataGenerator 中设置了 validation_split,则为数据子集(“training”或“validation”)。

    【讨论】:

      猜你喜欢
      • 2020-05-02
      • 2019-08-04
      • 1970-01-01
      • 1970-01-01
      • 2017-12-23
      • 2018-01-23
      • 1970-01-01
      • 1970-01-01
      • 2019-08-20
      相关资源
      最近更新 更多