I have 77 columns, with 4 class labels (already one-hot-encoded) by get_dummies.
x_train = X_train.reshape(-1, 1, 77)
x_test = X_test.reshape(-1, 1, 77)
y_train = y.reshape(-1, 1, 4)
y_test = y_test.reshape(-1, 1, 4)
batch_size = 32
model = Sequential()
model.add(Convolution1D(64, kernel_size=77, padding="same", activation="relu", input_shape=(77, 1)))
model.add(MaxPooling1D(pool_size=5))
model.add(BatchNormalization())
model.add(Bidirectional(LSTM(64, return_sequences=False)))
model.add(Reshape((128, 1), input_shape = (128, )))
model.add(MaxPooling1D(pool_size=5))
model.add(BatchNormalization())
model.add(Bidirectional(LSTM(128, return_sequences=False)))
model.add(Dropout(0.5))
model.add(Dense(5))
model.add(Activation('softmax'))
model.compile(loss='categorical_crossentropy',optimizer='adam',metrics=['accuracy'])
print(model.summary())
This is the model summary :
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
conv1d (Conv1D) (None, 77, 64) 4992
_________________________________________________________________
max_pooling1d (MaxPooling1D) (None, 15, 64) 0
_________________________________________________________________
batch_normalization (BatchNo (None, 15, 64) 256
_________________________________________________________________
bidirectional (Bidirectional (None, 128) 66048
_________________________________________________________________
reshape (Reshape) (None, 128, 1) 0
_________________________________________________________________
max_pooling1d_1 (MaxPooling1 (None, 25, 1) 0
_________________________________________________________________
batch_normalization_1 (Batch (None, 25, 1) 4
_________________________________________________________________
bidirectional_1 (Bidirection (None, 256) 133120
_________________________________________________________________
dropout (Dropout) (None, 256) 0
_________________________________________________________________
dense (Dense) (None, 5) 1285
_________________________________________________________________
activation (Activation) (None, 5) 0
=================================================================
Total params: 205,705
Trainable params: 205,575
Non-trainable params: 130
_________________________________________________________________
None
When I tried to fit the model:
history = model.fit(x_train, y_train,validation_data=(x_test,y_test), epochs=10)
I got this error :
raise ValueError(
ValueError: Input 0 of layer sequential_7 is incompatible with the layer: expected axis -1 of input shape to have value 1 but received input with shape (None, 1, 77)
What is wrong in the input_shape
?