Failed test case: first layer of the model has incorrect input shape. Expected: (None, 28, 28), but got: (32, 28, 28)

Failed test case: first layer of the model has incorrect input shape.
(None, 28, 28),
but got:
(32, 28, 28).

1 Like

x_train has shape of (60000, 28, 28). The first dimension is the number of examples. The last 2 dimensions are the shape of the image. You want to specify input_shape as the image dimensions and not the number of examples. Does this help?


@20JE0846_Sambhrant_D is your issue sorted?

No sir. Can you please describe what changes should I do in my code to get correct result. I had applied your hint but my percentage didn’t increased.

Is your code running now because previously I think you had raised issue of shapes not matching
Which percentage didn’t increase?The accuracy of model you mean?

Failed test case: model was not originally trained for 10 epochs.
but got:

Failed test case: first layer of the model has incorrect input shape.
(None, 28, 28),
but got:
(32, 28, 28).

I am getting these errors and my code is as follows:

[code removed - modetator]

You need to train on X_train,y_train while you have done that for the test split
Try doing training on the training split

Sir, can you please provide your solution because I am getting the same error while submission.

[code removed - moderator] While calling train_mnist call it in this way

Yes sir, I did but the error didn’t vanished. And my marks didn’t increase from 91 to 100.

The solution is to use the “batch_size” which does not divide without a remainder the size of the dataset (60000).
So, “batch_size” which will pass the grader, for example: 64.

I also want to point out that this part of the grader is poorly designed - so students have to guess “batch_size” which will allow to pass the assignment.

Sorry i had overlooked some cases which were the number of epochs for training are 10 and not 5 firstly
Also the parameter for callback is accuracy and not loss…please don’t think that loss=1-accuracy and give in callback as loss<0.01
Can you do these changes and try if it works
If not then you can change the learning_rate or batch size
Thanks @balaji.ambresh for helping me to see those.

I got the same error, and I’d like to understand it better.

The “None” in the expected shape means unknown, right? So, why would the grader take points off for the that part of the shape being specified? Is that value actually relevant to the code being evaluated here? The 28x28 part certainly is, but perhaps the test should ignore the first value in the tuple.

I’m also confused because some of the answers here talk about the batch_size parameter. I did not specify a batch_size at all, because that’s how we were taught to do it in the lecture and lab. Reading the documentation for Model, it says if bach_size is unspecified in the call to fit(), then it will default to 32. Perhaps this means the test case was written for a different version of the API (where the default value was None), and is broken now that the fit initializes to a default value of 32?

In either case, I feel like this test case is poorly written and deducting points unfairly. I’m not so concerned with my score, personally, but I do want the test to be correct for the sake of all the students. Is there any way to alert the course designers and get them to fix this?

I got the same error. I had my first layer (input layer) as “tf.keras.layers.Flatten().” After, I changed it to “tf.keras.layers.Flatten(input_shape=(28, 28))”. Then I got 100%.

In the course, we see that the first layer is coded in the both ways. Both of them should work the same. But, in the assignment the argument of input_shape needs to be passed in to get 100%. Hope this helps.

The default batch size in the call to fit() method will be 32 if and only if you didn’t batch your training/validation/test sets. On the other hand, if you have prepared batched dataset using API or using generators, then you can specify any batch size that can fit into the memory of your system.