Keras 1D convolution input form

I am trying to create a model for 1D convolution but I cannot get the correct input form. Here's what I have:

#this is actually shape (6826, 9000) but I am shortening it
train_dataset_x = np.array([[0, 1, 5, 1, 10], [0, 2, 4, 1, 3]])
#this is actually shape (6826, 1)
train_dataset_y = np.array([[0], [1]])

model.add(Conv1D(32, 11, padding='valid', activation='relu', strides=1, input_shape=( len(train_dataset_x[0]), train_dataset_x.shape[1]) ))
model.add(Conv1D(32, 3, padding='valid', activation='relu', strides=1) )
model.add(MaxPooling1D())

model.add(Conv1D(64, 3, padding='valid', activation='relu', strides=1) )
model.add(Conv1D(64, 3, padding='valid', activation='relu', strides=1) )
model.add(MaxPooling1D())


model.add(Flatten())
model.add(Dense(256, activation='relu'))
model.add(Dense(1, activation='sigmoid'))

      

I am getting this error:

ValueError: Error when checking input: expected conv1d_1_input to have 3 dimensions, but got array with shape (6826, 9000)

      

Anyone have any suggestions?

+3


source to share


1 answer


The entrance keras.layers.Conv1D

must be three-dimensional with dimensions (nb_of_examples, timesteps, features)

. I assume you have a 6000

1 function length sequence . In this case:

X = X.reshape((-1, 9000, 1))

      



The task must be completed.

+1


source







All Articles