I have a dataset which has two classes and has 400 features. Each feature is a floating point number. I am trying to build a basic CNN in keras but I am facing the following error. I have checked other solutions but those solutions ask to reshape the training data into (batch_size, steps, input_dim). I don't think that is a valid solution here.
My code and error message are posted below.
model = Sequential()
model.add(Dense(200, input_dim=400, init='glorot_uniform', activation='relu'))
model.add(Conv1D(100,
4,
padding='valid',
activation='relu',
strides=1))
model.add(GlobalMaxPooling1D())
model.add(Dense(50))
model.add(Activation('relu'))
model.add(Dense(1))
model.add(Activation('sigmoid'))
sgd = SGD(lr=0.01, decay=1e-6, momentum=0.9, nesterov=True)
model.compile(loss='binary_crossentropy', optimizer=sgd, metrics=['accuracy'])
return model
Error Message:
Traceback (most recent call last):
File "train_CNN.py", line 61, in <module>
model = create_baseline()
File "train_CNN.py", line 44, in create_baseline
strides=1))
File "/users/prateek.n/.local/lib/python2.7/site-packages/keras/models.py", li ne 469, in add
output_tensor = layer(self.outputs[0])
File "/users/prateek.n/.local/lib/python2.7/site-packages/keras/engine/topolog y.py", line 552, in __call__
self.assert_input_compatibility(inputs)
File "/users/prateek.n/.local/lib/python2.7/site-packages/keras/engine/topolog y.py", line 451, in assert_input_compatibility
str(K.ndim(x)))
ValueError: Input 0 is incompatible with layer conv1d_1: expected ndim=3, found ndim=2