简体   繁体   English

Keras flow_from_dataframe

[英]Keras flow_from_dataframe

I am trying to use keras flow_from_dataframe in order to augment the input images to my network (I am using the latest keras_preprocessing version).我正在尝试使用 keras flow_from_dataframe 来增加我网络的输入图像(我使用的是最新的 keras_preprocessing 版本)。 The network has an input image and an image as a label.该网络具有输入图像和作为标签的图像。 I have a csv file in the following format that specifies the input-output:我有一个指定输入输出的格式如下的 csv 文件:

Input,Output
E:\LTM\SCIE_DB\Dataset_Part1\Dataset\1\1.JPG,E:\LTM\SCIE_DB\Dataset_Part1\Label\1.JPG
E:\LTM\SCIE_DB\Dataset_Part1\Dataset\1\2.JPG,E:\LTM\SCIE_DB\Dataset_Part1\Label\1.JPG
E:\LTM\SCIE_DB\Dataset_Part1\Dataset\1\3.JPG,E:\LTM\SCIE_DB\Dataset_Part1\Label\1.JPG
E:\LTM\SCIE_DB\Dataset_Part1\Dataset\1\4.JPG,E:\LTM\SCIE_DB\Dataset_Part1\Label\1.JPG
E:\LTM\SCIE_DB\Dataset_Part1\Dataset\1\5.JPG,E:\LTM\SCIE_DB\Dataset_Part1\Label\1.JPG
E:\LTM\SCIE_DB\Dataset_Part1\Dataset\1\6.JPG,E:\LTM\SCIE_DB\Dataset_Part1\Label\1.JPG
E:\LTM\SCIE_DB\Dataset_Part1\Dataset\1\7.JPG,E:\LTM\SCIE_DB\Dataset_Part1\Label\1.JPG
E:\LTM\SCIE_DB\Dataset_Part1\Dataset\104\1.JPG,E:\LTM\SCIE_DB\Dataset_Part1\Label\104.JPG
E:\LTM\SCIE_DB\Dataset_Part1\Dataset\104\10.JPG,E:\LTM\SCIE_DB\Dataset_Part1\Label\104.JPG
E:\LTM\SCIE_DB\Dataset_Part1\Dataset\104\11.JPG,E:\LTM\SCIE_DB\Dataset_Part1\Label\104.JPG

I am trying to load the csv to a dataframe by the following code:我正在尝试通过以下代码将 csv 加载到数据帧:

df=pd.read_csv(r"E:\LTM\SCIE_DB\dataset.csv",names=("Input","Output"),dtype={"Input":"str","Output":"str"})
df = df.astype(str)
print(df.dtypes)

datagen=image.ImageDataGenerator(rescale=1./255)
train_generator=datagen.flow_from_dataframe(dataframe=df, directory=None, x_col="Input", y_col="Output", class_mode="other", target_size=(32,32), batch_size=32,has_ext = True)

However, I keep getting the following error :但是,我不断收到以下错误:

TypeError: y_col column/s must be numeric datatypes.

No matter what I am doing, I am unable to set the y_col as a str and it is always an object type.无论我在做什么,我都无法将 y_col 设置为 str 并且它始终是对象类型。 Any ideas?有任何想法吗?

Your values for y_col are of "string" type, but in your code you have refereed it as "numeric" since you specified class_mode as:您的 y_col 值是“字符串”类型,但在您的代码中,您已将其称为“数字”,因为您将 class_mode 指定为:

class_mode="other"

So change the class mode to所以将班级模式更改为

class_mode="input"

so you can use "string" values for y_col所以你可以为 y_col 使用“字符串”值

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

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