This error message indicates that there is a mismatch in the input dimensions of the LSTM layer in your model.
LSTM layers in Keras/TensorFlow expect input data to have 3 dimensions:
scss(batch_size, timesteps, input_dim)
However, it seems that the input data you are passing has only 2 dimensions:
scss(32, 128)
Here, (32, 128)
means that you have a batch of 32 sequences, each with 128 features.
To fix this error, you need to reshape your input data to have 3 dimensions. Depending on the format of your input data, you may need to use a function like np.reshape()
or tf.reshape()
to do this.
Assuming that your input data has shape (batch_size, input_dim)
, you can reshape it to have the required format using:
makefilenum_timesteps = 1 # Assuming you have only one timestep
input_dim = 128 # Assuming each sequence has 128 features
reshaped_input = np.reshape(input_data, (batch_size, num_timesteps, input_dim))
This will give you input data of shape (batch_size, 1, 128)
, which you can pass to the LSTM layer.
This error message indicates that there is a shape mismatch between the input data and the expected input shape of the LSTM layer lstm_23
.
In this code, lstm_23
refers to the third LSTM layer in your model. The error message is telling you that this layer expects a 3D input with shape (batch_size, timesteps, input_dim)
, but it received a 2D input with shape (32, 128)
.
The input shape of your model is (batch_size, 10080, 74)
, which means that each input sample has 10080 timesteps and 74 input features. However, in the first LSTM layer, you specified the input_shape
as (10080, 74)
which is redundant as you have already defined it in the Input
layer.
To fix this error, you need to remove the input_shape
argument from the first LSTM layer and also make sure that your input data has the correct shape. The shape of your input data should be (batch_size, 10080, 74)
.
Here's the modified code:
scssinputs = tf.keras.layers.Input(shape=(10080, 74), batch_size=BATCH_SIZE)
lstm_l1, state_h, state_c = LSTM(256, activation='relu', return_sequences=True, return_state=True)(inputs)
lstm_l2= LSTM(128, activation='relu')(lstm_l1)
lstm_l3 = LSTM(64, activation='relu')(lstm_l2)
dense_1 = Dense(1000, activation="relu")(lstm_l3)
outputs = Dense(1, activation="sigmoid")(dense_1)
model = tf.keras.Model(inputs=[inputs], outputs=[outputs])
model.compile(optimizer="adam", loss="binary_crossentropy", metrics=["accuracy"])
model.summary()
Make sure that your input data has the shape (batch_size, 10080, 74)
before passing it to the model.