CNN - Wk2 (Residual Networks) - Ex3 - ResNet50 Error: Inputs have incompatible shapes

Hi, I have been stuck on implementing the ResNet50() function. I am getting the ‘Inputs have incompatible shapes’ error.

Screenshot of the error message is attached. The error message seems to indicate a bug in Stage 2 of the model, and it is probably related to how X and X_shortchut are added. However my convolutional_block function passes the test.

Thanks for your help.

It’s an interesting error. From the source code that we can see in the exception trace, everything looks reasonable. The arguments you pass to the convolutional_block function at Stage 2 look correct, so there must be something going on that we can’t see there. It’s kind of hard to believe that there isn’t something wrong in your convolutional_block logic. One simple thing to try is to make sure your notebook is in a consistent state by doing the following steps:

Kernel → Restart and Clear Output
Cell → Run All

Then page through the notebook and make sure all the previous tests still pass and then see what the error message is in the ResNet50 test cell. Please try that and let us know If it still fails in the same way. If it fails, then we’ll probably need to see your source code in order to figure out what the problem is, but we aren’t supposed to do that on a public thread like this one. I’ll send you a DM about how to do that.

1 Like

To close the loop on the public thread: the clue here is that the ResNet50 test fails before it gets to any of the code that we need to add and it fails in convolutional_block. So that’s where the bug must be. It turns out that the stride values were hard-coded to (2,2) for the shortcut path instead of using the value of s that is actually passed in. The unfortunate thing is that passes the test case for convolutional_block, which must mean they are using the default value of 2 for that parameter in the test case. I’ll file an enhancement request and ask them to change the tests to catch that error.

1 Like

Oh what a silly mistake! Thanks Paul :grinning:.

I did have a hunch that it is to do with the stride parameter since the width and height of the tensor is off by a factor of two.