簡體   English   中英

使用多個輸入訓練 Keras 模型

[英]Training Keras model with multiple inputs

我想使用 keras 訓練一個具有 3 個不同輸入的模型。 訓練數據 - x_trainleft_trainright_train的形狀為 (10000,83,12)。 這是代碼的一部分。

from keras.layers import Dense, Input, LSTM
...
x = Input(shape = (83,12), dtype = "float32")
left = Input(shape = (83,12), dtype = "float32")
right = Input(shape = (83,12), dtype = "float32")
...
model = Model(inputs = [x, left, right], outputs = output)
model.compile(optimizer = "adadelta", loss = "categorical_crossentropy", metrics = ["accuracy"])
model.fit([x_train, left_train, right_train], y_train, validation_data=(x_test, y_test), epochs=20, batch_size=128)
...

我在訓練時收到以下錯誤:

ValueError                       Traceback (most recent call last)
<ipython-input-17-261d36872e91> in <module>()
     51 
     52 
---> 53 model.fit([x_train, left, right], y_train, validation_data= 
(x_test, y_test), epochs=20, batch_size=128)
     54 
     55 scores = model.evaluate(x_test, y_test)
     ...
     ValueError: Error when checking model input: the list of 
Numpy arrays that you are passing to your model is not the size the 
model expected. Expected to see 3 array(s), but instead got the 
following list of 1 arrays: [array(...

在調用fit方法時,我確實傳遞了 3 個輸入的列表。 有什么問題?

validation_datamodel.evaluate需要是多輸入的。 在您的情況下,您只提供一個數組(x_test, y_test)x_test ,它類似於([x_test, left_test, right_test], y_test) 本質上,驗證數據需要與訓練數據具有相同數量的輸入/輸出。

暫無
暫無

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

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