0

I use convolution 1D like this.

X_train[:, None].shape
X_train_t = X_train[:, None]
X_test_t = X_test[:, None]

K.clear_session()
model = Sequential()
model.add(Conv1D(39, 1, activation='relu', input_shape=(1,12)))

model.compile(loss='mean_squared_error', optimizer='adam' )

model.summary()

model.fit(X_train_t, y_train, epochs=200, batch_size=1, verbose=1)

y_pred = model.predict(X_test)

It show error like this

ValueError: Error when checking target: expected conv1d_1 to have 3 dimensions, but got array with shape (39, 1)

I print shape with this code print(X_train.shape) it show .

(39, 12)

If I change input_shape model to 1,1 .

model.add(Conv1D(39, 1, activation='relu', input_shape=(1,1)))

It show error.

ValueError: Error when checking input: expected conv1d_1_input to have shape (None, 1, 1) but got array with shape (39, 1, 12)

How to use convolution 1D ?

Mal Mmm
  • 17
  • 5

1 Answers1

0

Add model.add(Flatten()) in your code.

model = Sequential()
model.add(Flatten())
model.add(Conv1D(39, 1, activation='relu', input_shape=(1,12)))

model.compile(loss='mean_squared_error', optimizer='adam' )

model.summary()

model.fit(X_train_t, y_train, epochs=200, batch_size=1, verbose=1)

y_pred = model.predict(X_test)
Sociopath
  • 13,068
  • 19
  • 47
  • 75