簡體   English   中英

Keras flow_from_dataframe

[英]Keras flow_from_dataframe

我正在嘗試使用 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 並且它始終是對象類型。 有任何想法嗎?

您的 y_col 值是“字符串”類型,但在您的代碼中,您已將其稱為“數字”,因為您將 class_mode 指定為:

class_mode="other"

所以將班級模式更改為

class_mode="input"

所以你可以為 y_col 使用“字符串”值

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM