0

I am trying to build a simple Convolutional NN with:

  • 340 samples,
  • 260 rows per sample
  • 16 features per row.

I thought the order of the shape is (batch_size, steps, input_dim), which would mean (340, 16, 260) I believe.

Current code:

model = Sequential()
model.add(Conv1D(64, kernel_size=3, activation='relu', input_shape=(340, 16, 260)))
# model.add(Conv2D(64, 2, activation='relu'))
model.add(MaxPooling1D())
# model.add(Conv2D(128, 2, activation='relu'))
model.add(Conv1D(64, kernel_size=3, activation='relu'))
model.add(GlobalAveragePooling1D())
model.add(Dense(1, activation='linear'))

model.compile(loss='binary_crossentropy',
              optimizer='rmsprop',
              metrics=['accuracy'])

model.summary()

model.fit(xTrain, yTrain, batch_size=16, epochs=1000)

I am getting an error:

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

I am very lost and believe that my shapes are off. Could someone help me? Thank you!

dragon40226
  • 257
  • 1
  • 4
  • 11

1 Answers1

0

As mentioned in this answer, layers in Keras, accept two arguments: input_shape and batch_input_shape. The difference is that input_shape does not contain the batch size, while batch_input_shape is the full input shape, including the batch size.

Based on this, I think the specification input_shape=(340, 16, 260) tells keras to expect a 4-dimensional input, which is not what you want. The correct argument would be batch_input_shape=(340, 16, 260).

dynamicwebpaige
  • 373
  • 1
  • 10