PQMeng
PQMeng

Reputation: 61

mismatch in input_shape and model structure

This is the code:

model = Sequential()
model.add(LSTM(24, input_shape = (trainX.shape[0], 1, 4)))
model.add(Dense(12, activation = 'softmax'))
model.compile(loss='mean_squared_error', optimizer='adam')
model.fit(trainX, trainY, epochs=100, batch_size=1, verbose=2)

And after running, I got this:

ValueError: Input 0 is incompatible with layer lstm_5: expected ndim=3, found ndim=4

Can anyone explain this to me? and the relationship between input_shape and model structure.

Upvotes: 2

Views: 50

Answers (1)

Nicole White
Nicole White

Reputation: 7800

Your input_shape should be (trainX.shape[1], trainX.shape[2]). trainX.shape[0] is the number of training samples, which input_shape doesn't care about; input_shape only cares about the dimension of each sample, which is in the form (timesteps, features).

model.add(LSTM(24, input_shape = (trainX.shape[1], trainX.shape[2])))

Upvotes: 1

Related Questions