【发布时间】:2019-02-24 17:55:28
【问题描述】:
我正在尝试使用 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 并且它始终是对象类型。有什么想法吗?
【问题讨论】:
-
问题是str不是数字类型,y_col应该是整数或者浮点数,而不是字符串。
-
据我了解文档,y_col 可以是字符串。来自:keras.io/preprocessing/imagey_col:字符串或列表,数据框中包含目标数据的列。
-
我的意思是 y_col 的值可以是一个字符串,但它引用的列必须是数字,因为您将 class_mode 指定为“其他”。