【问题标题】:Training Keras model with multiple inputs使用多个输入训练 Keras 模型
【发布时间】:2019-01-23 15:29:11
【问题描述】:

我想使用 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 个输入的列表。有什么问题?

【问题讨论】:

    标签: python machine-learning keras deep-learning


    【解决方案1】:

    validation_datamodel.evaluate 也需要多输入。在您的情况下,您只提供一个数组(x_test, y_test)x_test,它类似于([x_test, left_test, right_test], y_test)。本质上,验证数据需要与训练数据具有相同数量的输入/输出。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-08-13
      • 2018-09-25
      • 1970-01-01
      • 1970-01-01
      • 2018-01-30
      • 1970-01-01
      • 2017-10-25
      相关资源
      最近更新 更多