Getting ValueError: Error when checking input: expected conv2d_1_input to have 4 dimensions, but got array with shape (315, 720, 1280)
See original GitHub issueHi,
I am trying to train a model on some grayscale images. The model I am using is:
model = Sequential()
model.add(Convolution2D(8, 3, 3, input_shape=(720, 1280,1)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(BatchNormalization())
model.add(Convolution2D(16, 3, 3))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(BatchNormalization())
#model.add(Dropout(0.6))
model.add(Convolution2D(32, 3, 3))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(BatchNormalization())
model.add(Convolution2D(64, 3, 3))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(BatchNormalization())
model.add(Dropout(0.5))
model.add(Flatten()) # this converts our 3D feature maps to 1D feature vectors
model.add(Dense(64))
model.add(Activation('relu'))
model.add(Dropout(0.5))
model.add(Dense(1))
model.add(Activation('sigmoid'))
Then I compile it:
model.compile(optimizer='rmsprop',
loss='categorical_crossentropy',
metrics=['accuracy'])
and then fit it:
model.fit(np.array(X_train), np.array(y_train_cat), batch_size=32,
epochs=10, verbose=1, validation_split=0.1)
The shape of the image is (1280,720) I get the error:
ValueError: Error when checking input: expected conv2d_1_input to have 4 dimensions, but got array with shape (315, 720, 1280)
If I don’t use the np.array
in fit, I get the following error:
Error when checking model input: the list of Numpy arrays that you are passing to your model is not the size the model expected. Expected to see 1 array(s), but instead got the following list of 315 arrays:
Can you please suggest what I should do? I have tried to resize it to 3D, something like (1280,720,1), but it’s not working.
Issue Analytics
- State:
- Created 5 years ago
- Comments:15 (1 by maintainers)
Top Results From Across the Web
deep learning - Error when checking model input: expected ...
Error when checking model input: expected convolution2d_input_1 to have 4 dimensions, but got array with shape (32, 32, 3) ; model = Sequential() ......
Read more >expected conv2d_1_input to have shape (3, 32, 32) but got ...
I want to train CNN for cifar10 datasets but got this error Error when checking input: ... epochs=epochs, batch_size=batch_size, verbose = 1)
Read more >'Error When Checking Model Input: Expected No Data, But Got ...
Ask questionsGetting ValueError: Error when checking input: expected conv2d1input to have 4 dimensions but got array with shape 315 720 1280.
Read more >I am having a hard time understanding the input shape in ...
Error when checking input: expected lstm_input to have 3 dimensions, but got array with shape (60, 8). Even though the training data consist ......
Read more >Error when checking model input: expected ... - YouTube
deep-learning: Error when checking model input : expected convolution2d_input_1 to have 4 dimensions, but got ar...Thanks for taking the time ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I used he numpy function to change the dimention to the image. The exact function I’ll send soon.
In reshaping our test images, we should be careful with input_size of the image like :
model.predict(X_train.reshape(10,28,28,1)
-->for 10 input images.If we want to predict for single instance of image, we should consider only one image but not number of features. (Features could be what ever, like 789 or 287 e.t.c…)
model.predict(X_train.reshape(1,28,28,3))