我正在使用 Keras 影像資料生成器進行資料增強,以及其中的 flow_from_dataframe 函式。關于它的資訊在這里:https ://www.tensorflow.org/api_docs/python/tf/keras/preprocessing/image/ImageDataGenerator#flow_from_dataframe
# Create new dataframes for train and test
df_train = pd.DataFrame()
df_train['image'], df_train['labels'] = X_train, y_train
df_test = pd.DataFrame()
df_test['image'], df_test['labels'] = X_test, y_test
這是一個資料框的樣子:
image labels
4227 /Users/m/Documents/Machine Learning Pr... [73, 0]
4676 /Users/m/Documents/Machine Learning Pr... [36, 0]
800 /Users/m/Documents/Machine Learning Pr... [26, 0]
3671 /Users/m/Documents/Machine Learning Pr... [42, 0]
這就是我匯入資料生成器的方式:
from keras.preprocessing.image import ImageDataGenerator
datagen = ImageDataGenerator(
rescale = 1./255,
rotation_range = 40,
width_shift_range = 0.2,
height_shift_range = 0.2,
shear_range = 0.2,
zoom_range = 0.2,
horizontal_flip = True,
fill_mode = 'nearest'
)
test_datagen= ImageDataGenerator(rescale=1./255.)
train_generator=datagen.flow_from_dataframe(
dataframe = df_train,
x_col="image",
y_col="labels",
batch_size=32,
seed=42,
shuffle=True,
class_mode='multi_output',
target_size=(128, 128))
valid_generator = test_datagen.flow_from_dataframe(
dataframe = df_test,
x_col = "image",
y_col = "labels",
batch_size = 32,
seed = 42,
shuffle = True,
class_mode='multi_output',
target_size=(128, 128))
該函式讀入一個資料框,但在檔案中它說指定的 y_col 必須是一個串列:
y_col 字串或串列,資料框中包含目標資料的列。
在我創建資料框之前,該列是一個串列,但現在它是 pandas 中的一個列,它不再被歸類為“串列”,對吧?那么為什么我會收到此錯誤訊息:
TypeError: If class_mode="multi_output", y_col must be a list. Received str.
我想使用上面的類模式多輸出,它宣告 y_col 必須是一個串列,但它是一個字串。不知道為什么它說它是一個字串?無論如何要更改資料框中列的“型別”還是我誤解了?
uj5u.com熱心網友回復:
這里的“串列”表示列名串列。
正如 Zelemist 所說,更改您的資料框,以便有兩列而不是您擁有的那一列。
然后向 y_col 輸入一個串列,例如:
y_col = ['col1', 'col2]
希望現在有意義。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/531557.html
標籤:熊猫列表喀拉斯