0

I have two data. One is time series and the other contains features such as Sex, education, etc. and I want to concatenate output of LSTM model and a dense model. However, I got an error message (look at the end).

This is what the data looks like:

enter image description here

enter image description here

And this is the code:

# PAY_data net
input1 = Input(shape=(6,1))
pay = LSTM(10)(input1)
pay = Dense(10, activation='relu')(pay)

# DEMO_data net
input2 = Input(shape=(5,1))
demo = Dense(10, activation='relu')(input2)
demo = Dense(10, activation='relu')(demo)

merge = concatenate([pay, demo])

hidden1 = Dense(10, activation='relu')(merge)

output = Dense(1, activation='sigmoid')(merge)
model = Model(inputs=[input1, input2], outputs=output)

print(model.summary())

model.compile(loss='binary_crossentropy', optimizer='adam', metrics=    ['accuracy'])

model.fit([PAY_data, DEMO_data], y,nb_epoch=20, batch_size=50, verbose=2, validation_split=0.2)

and this is the error I get:

enter image description here

today
  • 32,602
  • 8
  • 95
  • 115
MinJae
  • 11
  • 1
  • If the answer resolved your issue, kindly *accept* it by clicking on the checkmark next to the answer to mark it as "answered" - see [What should I do when someone answers my question?](https://stackoverflow.com/help/someone-answers) – today Nov 26 '18 at 15:53

1 Answers1

0

Since the Dense layer is applied on the last axis of its input data, and considering that you have specified an input shape of (5,1) for your "Demo_data net", the output shape of this model would be (None, 5, 10) and therefore it cannot be concatenated with the output of the "Pay_data net" which has an output shape of (None, 10). To resolve this, you can remove the redundant last axis from PAY_data using np.squeeze():

PAY_data = np.squeeze(PAY_data)

and also set the input shape accordingly:

input2 = Input(shape=(5,))  # now the input shape is (5,) and not (5,1)
today
  • 32,602
  • 8
  • 95
  • 115