Skip to content
Advertisement

proper input and output shape of a keras Sequential model

I am trying to run a Keras sequential model but can’t get the right shape for the model to train on.

I reshaped x and y to:

JavaScript

Currently, both the input shape and output shape are:

JavaScript

The dataset consists of 9766 inputs and 9766 outputs respectively. Each input is a single array of 500 values and each output is also an array of 500 values.

So here is one single input array:

JavaScript

And here is one output array:

JavaScript

And this is the model I am trying to train the data on (most likely with a bad architecture):

JavaScript

How I would like the model to train is to see the input and produce an array of 500 values like the output array shown above. But no matter what shape I try, I get an error like the following:

JavaScript

What shape is the proper shape here and what am I doing wrong with the model architecture?

UPDATE 1:

I also tried reshaping x and y to:

JavaScript

still no luck.

Advertisement

Answer

LSTM layer expects input shape as [batch, timesteps, feature]. So, with the shape (9766, 1, 500), you have one timestep with 500 features. If you have 500 timesteps, your shape should be like (9766, 500, 1).

Here is an example architecture:

JavaScript

If you check the model summary, you see input and output shape are the same as you expected:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement