# Error with MSE in LSTM

I'm trying to fit an LSTM model on my dataset, using also a validation set. My datasets have the following shapes:

X_train = (56054, 250, 30) #where 250 = sequence_length
X_val = (13969, 250, 30) #where 250 = sequence_length


This is the model I created:

cbs = [History(), EarlyStopping(monitor='val_loss',
patience=3, min_delta=0.0003, verbose=0),
TensorBoard(log_dir='Baseline/tb_logsLSTM', histogram_freq=1, write_images=True)]

model = Sequential()

return_sequences=True))
return_sequences=False))
model.compile(loss='mse',
model.fit(X_train, X_train,
batch_size=60,
epochs=35,
validation_data=(X_val, X_val),
callbacks=cbs, verbose=True)


When I run it, it finish the first epoch and give me this error in the fit function:

tensorflow.python.framework.errors_impl.InvalidArgumentError:  Incompatible shapes: [64,30] vs. [64,250,30]


How can I solve it?

It seems a couple of things can be done differently.

Firstly, it seems you are passing train and label data incorrectly when fitting the model. It should be more like:

model.compile(loss='mean_squared_error', optimizer='adam')
model.fit(trainX, trainY, epochs=100, batch_size=1, verbose=2)


For trainY being your labels, as opposed to passing trainX twice as in your code above. Same applies for your validation_data argument.

Secondly, what is the role of a linear activation in your code? You could simply close your computational graph with the dense layer e.g.

model = Sequential()