Reputation: 27
I've just started using Keras. I encountered a problem that how to feed multiple outputs of previous layers to a successive lstm layer. My model(part) is just like below:
batch_size = 64
output_1 = Dense(output_dim=(128, ), input_dim=(200, ))
output_2 = Dense(output_dim=(128,), input_dim=(200, ))
output_3 = Dense(output_dim=(128,), input_dim=(200, ))
output_4 = Dense(output_dim=(128,), input_dim=(200, ))
Now my problem is how to feed all above outputs to a lstm ? the input_dim should be like (batch_size, number_of_previous_outputs, 128)
Upvotes: 1
Views: 774
Reputation: 7148
You can do a merge layer (https://keras.io/getting-started/sequential-model-guide/#the-merge-layer). Either with concat or with sum to and then feed the merge layer into the lstm.
code example:
merged_output = merge([output_1, output_2, output_3, output_4], mode='concat', concat_axis=1)
lstm = LSTM(...)(merged_output)
Upvotes: 1