简体   繁体   中英

Input dimension issue of Conv1D network

As I am new in Deep Learning field, I am facing a strange issue regarding the input shape of my Convolutional network (1D). The input is normalized values of 13 features and total 7866 samples are available

x_train_shape (7866, 13)

The target is 0 or 1 for each features.

y_train.shape (7866, 13)

I am using following simple 1D conv network just to see how it performs.

from keras.models import Sequential
model = Sequential()
model.add(Conv1D(filters=64, kernel_size=1,
                 activation='relu', input_shape=(13,1)))

model.add(Conv1D(filters=64, kernel_size=1, activation='relu'))
model.add(Dropout(0.5))
model.add(MaxPooling1D(pool_size=2))
model.add(Flatten())
model.add(Dense(100, activation='relu'))
model.add(Dense(13, activation='softmax'))
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
model.summary()
history = model.fit(x_train, y_train, epochs=20, verbose=0)

It shows the summary of the network but also raises this error:

Error when checking input: expected conv1d_1_input to have 3 dimensions, but got array with shape (7866, 13)

I tried to implement different solutions from here and here . So when

input_shape = (13,)

is used, it raises a different error like this:

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

Can anyone please enlighten me what is the proper input_shape for this network and why?
NB x_train and y_train are in pandas dataframe format. Is that causing any issues, should I have to convert it to another format?

Keeping the input_shape argument the same, you should add a dimension to your input, or " unsqueeze " it.

x_train = np.expand_dims(x_train, 0)

Its shape will now be:

(7866, 13, 1)

Reshape your training data as follows: Then run your model

x_train.reshape(7866, 13,1)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM