1
$\begingroup$

I have X_train and Y_train with [2160,24,3] dimensions. But when I try a simple LSTM like this:

model = Sequential()
model.add(LSTM(24 , return_sequences = True))
model.add(Dropout(dp)) 

It gives me this error message:

ValueError: Error when checking target: expected dropout_192 to have shape (24, 24) but got array with shape (24, 3)

And when I try to change my code like this:

model = Sequential()
model.add(LSTM(24 , return_sequences = False))
model.add(Dropout(dp)) 

model.add(RepeatVector(24))

I get:

ValueError: Error when checking target: expected repeat_vector_55 to have shape (24, 24) but got array with shape (24, 3)

Also:

model = Sequential()
model.add(LSTM(24 , return_sequences = False))
model.add(Dropout(dp))   
model.add(RepeatVector(24))
model.add(TimeDistributed(Dense(1))) 

Or:

model = Sequential()
model.add(LSTM(24 , return_sequences = False))
model.add(Dropout(dp))   
model.add(RepeatVector(24))
model.add(LSTM(24 , return_sequences = True))
model.add(Dropout(dp)) 
model.add(TimeDistributed(Dense(1))) 

Gives me:

ValueError: Error when checking target: expected time_distributed_56 to have shape (24, 1) but got array with shape (24, 3)

I am confused and don't know how to fix it? What I want is train a LSTM model with X_train and Y_train of size [2160,24,3]. How can I do that?

$\endgroup$
1
$\begingroup$

In all the above cases, you are not setting the output shape properly. The last layer should create 3 features. Try this for example:

model = Sequential()
model.add(LSTM(24, return_sequences = True))
model.add(Dropout(dp)) 
model.add(Dense(3))
$\endgroup$
  • $\begingroup$ Thank you SaTa, it worked, but a new problem arrived! When I try model.predict(X_test) that X_test has a [6,24,3] shape, I get a [432,1] shape result, but I expected a shape as same as the X_test for my result. So how can I fix it? $\endgroup$ – user3486308 Jul 6 '19 at 13:56
  • $\begingroup$ That's odd. Did you get this with the above code? If not, can you post your code? $\endgroup$ – SaTa Jul 6 '19 at 14:38
  • $\begingroup$ Yes, I changed the Dense layer's input to 3, then used that code but got predicted result in a [432,1] array instead of [6,24,3]. $\endgroup$ – user3486308 Jul 6 '19 at 16:13
  • $\begingroup$ No, sorry. You are right. I was reshaping the result array in some part of my code! Thank you again! $\endgroup$ – user3486308 Jul 6 '19 at 16:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.