Keras - Making two predictions from one neural network

ⅰ亾dé卋堺 提交于 2019-12-06 07:50:32

You don't need to concatenate the outputs, your model can have two outputs:

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])

Then to train this model, you typically use two losses that are weighted to produce a single loss:

model.compile(optimizer='sgd', loss=['categorical_crossentropy', 
              'categorical_crossentropy'], loss_weights=[0.2, 0.8])

Just make sure to format your data right, as now each input sample corresponds to two output labeled samples. For more information check the Functional API Guide.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!