Keras flow_from_dataframe

时间:2019-02-24 17:55:28

标签: python keras

我正在尝试使用keras flow_from_dataframe来将输入图像扩展到我的网络(我正在使用最新的keras_preprocessing版本)。网络具有输入图像和作为标签的图像。我有以下格式的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

我正在尝试通过以下代码将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)

但是,我不断收到以下错误消息:

TypeError: y_col column/s must be numeric datatypes.

无论我在做什么,我都无法将y_col设置为str,并且它始终是对象类型。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

您的y_col值是“字符串”类型,但是在您的代码中,由于您将class_mode指定为以下内容,因此您将其称为“数字”:

class_mode="other"

因此将课堂模式更改为

class_mode="input"

因此您可以为y_col使用“字符串”值

相关问题