-
Notifications
You must be signed in to change notification settings - Fork 19.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ValueError: Error when checking input: expected input_1 to have 4 dimensions, but got array with shape (2120, 1) #12318
Comments
The error seems to indicate that the X_train parameter that you passed to model.fit has a shape of (2120, 1). The resnet model expects a shape of (batch_size, 3, 224, 224) by default. I would recommend that you print the shapes of the parameters to model.fit() and also use model.summary() to display the expected shapes of the network. |
Also facing this issue. My data has a shape of (900, 300, 250, 3) but as soon as I increase the training set to 1000 images, I get the following shape (1000,). One thing to note is that I'm facing this problem only on Google Colab notebook and not on Jupyter where my training data shape is (1000, 300, 250, 3) with the same code |
The problem most probably that you have a none 300*250 image leaked into your dataset. Please make sure your data is matching. To have a N-dimensional array you have to have all dimension matching through your dataset. And on top of that your datatype should be the same. If you would have even one image that is not the same dimensions of others you would have a Structured array, thus your array shape would become N,1 instead of N,H,W,C. |
I'm facing the same issue VGG16 Model while taking the input from a different source and the eroor comes as: ValueError: Error when checking input: expected input_2 to have shape (224, 224, 3) but got array with shape (224, 224, 4) |
I am facing similar problem and converting input and output arrays to |
adding extra bracket on the x_train and y_train and converting them to array solved it for me |
I have the same problem, I try to convert to array as said, but didn't solved the problem... My error: ValueError: Error when checking input: expected input_4 to have shape (None, 600) but got array with shape (600, 21661) |
Hey everyone,
I'm trying to use custom data on the resnet 50 model, but it keeps giving shape errors. After reading some other issues along the same lines.Any thoughts?
if name == 'main':
Load our model
model = resnet50_model(img_rows, img_cols, channel, num_classes)
model.fit(X_train, Y_train,
batch_size=batch_size,
nb_epoch=nb_epoch,
shuffle=True,
verbose=1,
validation_data=(X_test, Y_test),
)
Make predictions
predictions_valid = model.predict(X_test, batch_size=batch_size, verbose=1)
Cross-entropy loss score
score = log_loss(Y_test, predictions_valid)
output:
ValueError Traceback (most recent call last)
in
18 shuffle=True,
19 verbose=1,
---> 20 validation_data=(X_test, Y_test),
21 )
22
~/anaconda3/envs/py36/lib/python3.6/site-packages/keras/engine/training.py in fit(self, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, steps_per_epoch, validation_steps, **kwargs)
950 sample_weight=sample_weight,
951 class_weight=class_weight,
--> 952 batch_size=batch_size)
953 # Prepare validation data.
954 do_validation = False
~/anaconda3/envs/py36/lib/python3.6/site-packages/keras/engine/training.py in _standardize_user_data(self, x, y, sample_weight, class_weight, check_array_lengths, batch_size)
749 feed_input_shapes,
750 check_batch_axis=False, # Don't enforce the batch size.
--> 751 exception_prefix='input')
752
753 if y is not None:
~/anaconda3/envs/py36/lib/python3.6/site-packages/keras/engine/training_utils.py in standardize_input_data(data, names, shapes, check_batch_axis, exception_prefix)
126 ': expected ' + names[i] + ' to have ' +
127 str(len(shape)) + ' dimensions, but got array '
--> 128 'with shape ' + str(data_shape))
129 if not check_batch_axis:
130 data_shape = data_shape[1:]
ValueError: Error when checking input: expected input_1 to have 4 dimensions, but got array with shape (2120, 1)
The text was updated successfully, but these errors were encountered: