我想使用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_test)
。本质上,验证数据需要与训练数据具有相同数量的输入/输出。