简体   繁体   中英

ValueError: Error when checking input: expected conv1d_81_input to have shape (177, 100) but got array with shape (1, 177)

I've got this error in my code can anyone help me ?? How to fix the input array to meet the input shape?

my data is :{The original dataset from the reference consists of 5 different folders, each with 100 files, with each file representing a single subject/person. Each file is a recording of brain activity for 23.6 seconds. The corresponding time-series is sampled into 4097 data points. Each data point is the value of the EEG recording at a different point in time. So we have total 500 individuals with each has 4097 data points for 23.5 seconds.

We divided and shuffled every 4097 data points into 23 chunks, each chunk contains 178 data points for 1 second, and each data point is the value of the EEG recording at a different point in time. So now we have 23 x 500 = 11500 pieces of information(row), each information contains 178 data points for 1 second(column), the last column represents the label y {1,2,3,4,5}. }

cvacc =[]
j=0
kf=KFold(n_splits=10, random_state=None, shuffle=False)
for train_index, test_index in kf.split(X):
    print('\nFold ',j)
    X_train, X_test = X[train_index], X[test_index] 
    y_train, y_test = y[train_index], y[test_index]

    # create model
    # 1D CNN neural network
    model = Sequential() 
    model.add(Conv1D(filters=10, kernel_size=10,             
    strides=1,activation='relu', input_shape=(3450,177)))
    model.add(Conv1D(filters=10, kernel_size=10, strides=1))
    model.add(MaxPooling1D(2))
    model.add(Conv1D(30,10,activation='relu', strides=1))
    model.add(Conv1D(30,10,activation='relu', strides=1))
    model.add(MaxPooling1D(2))
    model.add(Conv1D(60,10,activation='relu', strides=1))
    model.add(Conv1D(60,10,activation='relu', strides=1))
    model.add(MaxPooling1D(2))
    model.add(Conv1D(90,10,activation='relu', strides=1))
    model.add(Conv1D(90,10,activation='relu', strides=1))
    model.add(MaxPooling1D(2))
    model.add(Conv1D(120,10,activation='relu', strides=1))
    model.add(Conv1D(120,10,activation='relu', strides=1))
    model.add(MaxPooling1D(2))
    model.add(Flatten())
    model.add(Dense(50))
    model.add(Dense (20))
    model.add(Dense (5,activation='softmax'))
    # print(model.summary())

    model.compile(loss='categorical_crossentropy',
          optimizer='adam',
          metrics=['accuracy'])

    print(X_train.shape)
    print(X_test.shape)
# X_train= 
np.reshape(X_train(X_train.shape[0],X_train.shape[1],X_train.shape[1]))

history=model.fit(X_train, y_train, batch_size=3, 
epochs=15,validation_split=0.1)

Acc. to doc https://keras.io/layers/convolutional/ , your input should be a 3D tensor of shape (batch_size, steps, input_dim) where batch_size is the number of series in the batch, steps is the number of time steps in the series, input_dim is the dimension of one step in the series. For you, steps = 178 .

Try changing the first line in the model to :

model.add(Conv1D(filters=10, kernel_size=10,             
    strides=1,activation='relu', input_shape=(178, 1)))

(We needn't mention the batch_size value. It can be left uncertain till training.)

Your training data must satisfy these dimensions. X_train.shape should be (*, 178, 1)

Note: You will get further errors since the layers are not proper. After the third pooling layer, the number of steps will be 6, and the next convolution layer has a stride of 10 (> 6), and will give errors. You have to reconfigure the layers.

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