Reputation: 69
I want to train a model with 3 different inputs using keras. The training data - x_train, left_train, right_train is of shape (10000,83,12). Here is part of the code.
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)
...
I am getting the following error while training:
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(...
I do pass a list of 3 inputs when calling fit method. What's the problem?
Upvotes: 4
Views: 8438
Reputation: 11225
The validation_data
and model.evaluate
needs to be multi-input as well. In your case you only provide a single array (x_test, y_test)
and just x_test
where it would be something similar to ([x_test, left_test, right_test], y_test)
. Essentially, the validation data needs to have same number of inputs / outputs as the training data.
Upvotes: 6