我想使用 keras 训练具有 3 个不同输入的模型。训练数据 - x_train、left_train、right_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_data
和 model.evaluate
也需要是多输入的。在您的情况下,您只提供一个数组 (x_test, y_test)
和 x_test
,它类似于 ([x_test, left_test, right_test], y_测试)
。本质上,验证数据需要具有与训练数据相同数量的输入/输出。
关于python - 使用多个输入训练 Keras 模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54330586/