如何正确使用Keras Add层?

时间:2019-11-30 18:19:40

标签: python tensorflow keras

我试图将两个LSTM层合并在一起,但是没有成功。

answers_questions_lstm = LSTM(256,input_shape=(8,4,))
answers_contexts_lstm = LSTM(256,input_shape=(10,6,))
answers_combined_lstm = Add()([answers_questions_lstm,answers_contexts_lstm])
answers_hidden_1 = Dense(124)(answers_combined_lstm)
answers_output = Dense(outputTrain.shape[1])
answers_network_1.summary()

这给了我“应该在输入列表上调用合并层”。为什么?

1 个答案:

答案 0 :(得分:3)

由于您使用的是Keras Functional API,因此应该从一些Input图层开始。然后在Inputs上调用您的LSTM层以获取张量输出,然后将其传递到Add层:

A, B,....Z, A, B,....