sample , label input shape - LSTM

My dataset shape is (8968, 1024). In order to use it as an input for LSTM, I converted it to 3D samples = np.asarray(samples).reshape(1,8968,1024)

Model:

input = layers.Input(shape=(1024,))
model = tf.keras.Sequential()
model.add(layers.Bidirectional(LSTM(256, return_sequences=True, activation='relu'), 
input_shape=(8968,1024)))
model.add(layers.Bidirectional(LSTM(128,  activation='relu')))
model.add(layers.Dense(32,  activation='relu'))
model.add(layers.Dense(num_classes, activation=activation))

However, when running the code below I'm getting an error

code:

def train_model(X,
            y,
            fname,  # Path where to save the model
            activation='softmax',
            epochs=1,
            optimizer='adam',
            num_hidden=64,
            batch_size=128
            ):    
X, labels = shuffle(X, y)

X_train, X_test, y_train, y_test = train_test_split(X, labels, test_size=0.20)

history = general_model.fit(X_train, y_train, epochs=EPOCHS, validation_split=0.20, batch_size=BATCH_SIZE,
                            callbacks=callbacks, verbose=1)

Error:

ValueError: Found input variables with inconsistent numbers of samples: [1, 8968]

I understand that there is a difference in the size between the samples and the labels, but even when I did X = X.reshape(X.shape[1:]) X = X.transpose()

I'm still getting the below error:

ValueError: Found input variables with inconsistent numbers of samples: [1024, 8968]

I'm not sure what I'm doing wrong.

Topic reshape lstm keras python

Category Data Science

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.