Model Set Code
EPOCHS = 1
x_tr = np.reshape(X_train, (X_train.shape[0], 1, X_train.shape[1]))
x_ts = np.reshape(X_test, (X_test.shape[0], 1, X_test.shape[1]))
model = Sequential()
model.add(LSTM(units=390, input_shape = (1,X_train.shape[1]), return_sequences = True))
model.add(LSTM(units=260, return_sequences=True))
model.add(Dropout(0.2))
model.add(LSTM(units=190, return_sequences=True))
model.add(Dropout(0.2))
model.add(LSTM(units=160, return_sequences=True))
model.add(Dropout(0.3))
model.add(LSTM(units=60, return_sequences=True))
model.add(Dropout(0.2))
model.add(LSTM(units=90, return_sequences=True, name='output'))
model.add(Dense(6,activation='sigmoid'))
#Compiling the model
model.compile(loss='categorical_crossentropy',optimizer='adam',metrics=['accuracy'])
print(model.summary())
y_train = to_categorical(y_train)
y_test = to_categorical(y_test)
y_train = np.reshape(y_train, (y_train.shape[0], -1, y_train.shape[1]))
y_test = np.reshape(y_test, (y_test.shape[0], -1, y_test.shape[1]))
# Fitting with 1000 epochs and 20 batch size
model.fit(x_tr, y_train, validation_data=(x_ts, y_test),epochs=EPOCHS,batch_size=20)
This is the error that is showing whenever I run the Code. i don't know which type of error is existing
ValueError: in user code:
File "/usr/local/lib/python3.7/dist-packages/keras/engine/training.py", line 1021, in train_function *
return step_function(self, iterator)
File "/usr/local/lib/python3.7/dist-packages/keras/engine/training.py", line 1010, in step_function **
outputs = model.distribute_strategy.run(run_step, args=(data,))
File "/usr/local/lib/python3.7/dist-packages/keras/engine/training.py", line 1000, in run_step **
outputs = model.train_step(data)
File "/usr/local/lib/python3.7/dist-packages/keras/engine/training.py", line 860, in train_step
loss = self.compute_loss(x, y, y_pred, sample_weight)
File "/usr/local/lib/python3.7/dist-packages/keras/engine/training.py", line 919, in compute_loss
y, y_pred, sample_weight, regularization_losses=self.losses)
File "/usr/local/lib/python3.7/dist-packages/keras/engine/compile_utils.py", line 201, in __call__
loss_value = loss_obj(y_t, y_p, sample_weight=sw)
File "/usr/local/lib/python3.7/dist-packages/keras/losses.py", line 141, in __call__
losses = call_fn(y_true, y_pred)
File "/usr/local/lib/python3.7/dist-packages/keras/losses.py", line 245, in call **
return ag_fn(y_true, y_pred, **self._fn_kwargs)
File "/usr/local/lib/python3.7/dist-packages/keras/losses.py", line 1790, in categorical_crossentropy
y_true, y_pred, from_logits=from_logits, axis=axis)
File "/usr/local/lib/python3.7/dist-packages/keras/backend.py", line 5083, in categorical_crossentropy
target.shape.assert_is_compatible_with(output.shape)
ValueError: Shapes (None, 512, 2) and (None, 1, 6) are incompatible