您不需要连接输出,您的模型可以有两个输出:
input = Input(shape=(100, 100), name='input')
lstm = LSTM(128, input_shape=(100, 100)))(input)
output1 = Dense(len(4), activation='softmax', name='output1')(lstm)
output2 = Dense(len(10), activation='softmax', name='output2')(lstm)
model = Model(inputs=[input], outputs=[output1, output2])
然后,为了训练该模型,您通常使用两个加权损失来产生一个损失:
model.compile(optimizer='sgd', loss=['categorical_crossentropy',
'categorical_crossentropy'], loss_weights=[0.2, 0.8])
只需确保正确设置数据格式,因为现在每个输入样本对应于两个输出标记样本。欲了解更多信息,请查看功能性API指南 https://keras.io/getting-started/functional-api-guide/.