1

I am trying to make a model using Keras with LSTM autoencoder. Here what I have tried

data = df.values
timesteps = 10
dim = data.shape[1]
samples = data.shape[0]
data.shape = (int(samples/timesteps),timesteps,dim)

and then

model = Sequential()
model.add(LSTM(50,input_shape=(timesteps,dim),return_sequences=True))
model.add(LSTM(50,input_shape=(timesteps,dim),return_sequences=True))
model.add(LSTM(50,input_shape=(timesteps,dim),return_sequences=True))
model.add(LSTM(50,input_shape=(timesteps,dim),return_sequences=True))
model.add(LSTM(50,input_shape=(timesteps,dim),return_sequences=True))
model.add(LSTM(50,input_shape=(timesteps,dim),return_sequences=True))
model.add(LSTM(50,input_shape=(timesteps,dim),return_sequences=True))
model.add(LSTM(50,input_shape=(timesteps,dim),return_sequences=True))
model.add(LSTM(50,input_shape=(timesteps,dim),return_sequences=True))
model.add(LSTM(50,input_shape=(timesteps,dim),return_sequences=True))
model.add(LSTM(50,input_shape=(timesteps,dim),return_sequences=True))
model.compile(loss='mae', optimizer='adam')

this is my model fit

model.fit(data, data, epochs=50, batch_size=72, validation_data=(data, data), verbose=0, shuffle=False)

This is the error message I am getting

ValueError: Error when checking target: expected lstm_33 to have shape (None, 10, 50) but got array with shape (711, 10, 1)

How can I fix this ?

I have only I data set

Update

input data shape I have = (7110, 1)

This is an Univariate time series data

3
  • On which layer you fail? the first? also post your data.shape, you define dim = data.shape[1] but then use it as data.shape[2]? Commented Dec 18, 2018 at 19:46
  • input shape is (7110, 1) Commented Dec 18, 2018 at 19:52
  • 1
    This isn't specific to your question, but I noticed your error says lstm_33, so that means it is keeping all of your layers from previous runs. If you run from keras import backend then backend.clear_session() between model builds, then you'll start with a fresh graph and it would start from lstm, lstm_1, etc. Commented Dec 18, 2018 at 21:37

1 Answer 1

3

The error is caused by specifying input_shape=(timesteps,dim) for all the layers. You only need to do this for the first layer and the rest will be inferred by the previous layer. What is happening is you are overriding the input shape which is causing the error.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, I just fixed it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.