Error when checking model input: expected convolution2d_input_1 to have 4 dimensions, but got array with shape (32, 32, 3)

后端 未结 9 1689
南笙
南笙 2020-12-08 01:28

I want to train a deep network starting with the following layer:

model = Sequential()
model.add(Conv2D(32, 3, 3, input_shape=(32, 32, 3)))

9条回答
  •  被撕碎了的回忆
    2020-12-08 02:23

    I got the same error while working with mnist data set, looks like a problem with the dimensions of X_train. I added another dimension and it solved the purpose.

    X_train, X_test, \ y_train, y_test = train_test_split(X_reshaped, y_labels, train_size = 0.8, random_state = 42)

    X_train = X_train.reshape(-1,28, 28, 1)

    X_test = X_test.reshape(-1,28, 28, 1)

提交回复
热议问题