Coding problems in Course 4, Resnet notebook, exercise 2

I have a coding problem in deep learning, Course 4, Resnet notebook, exercise 2 (I completed exercise 1 with no problems) exercise 2 appears similar and I have rechecked the code but I continue to get the following error ( from the following module regarding exercise 2):

Here is the error message:

tf.Tensor(
[[[0. 0. 0. 0.03110444 0. 0.2228643 ]
[0. 0. 0. 0.01448277 0. 0.11220478]]

[[0. 0. 0. 0.00741222 0. 0.18840416]
[0. 0. 0. 0. 0. 0.11712705]]], shape=(2, 2, 6), dtype=float32)

AssertionError Traceback (most recent call last)
Input In [17], in <cell line: 3>()
1 ### you cannot edit this cell
----> 3 public_tests.convolutional_block_test(convolutional_block)

File /tf/W2A1/public_tests.py:111, in convolutional_block_test(target)
108 tf.keras.backend.set_learning_phase(True)
110 B = target(X, f = 2, filters = [2, 4, 6])
→ 111 assert np.allclose(B.numpy(), convolutional_block_output2), “Wrong values when training=True.”
113 print(‘\033[92mAll tests passed!’)

AssertionError: Wrong values when training=True.

Thanks for any help you could give

This whole assignment is an excruciating exercise in proofreading. There are lots of details to get write: filter sizes, strides, padding. But one very common mistake is not to use the correct input to the “shortcut” path. The instructions are maybe not as clear on this point as the diagram. The classic case of the picture being worth more than words. :nerd_face:

Thanks for your suggestion. It seems to me that the error is in using F3 instead of F1 in the first line of the ‘shortcut code’ as F1 addresses the initial output before the skip step. So I changed F3 to F1 in that code (as below) but I still get an error. Do I also need to change the (s,s) back to (1,1)?

{moderator edit - solution code removed}

From the instructions:

Yes, you have made several mistakes there. The big one is using the wrong input to the shortcut step, just as I feared. And then you also made the mistake of not using the parameters for that step as they specified in the instructions. To be fair, they are about as explicit as possible w.r.t. the parameters without actually writing out the code for you. (As Tom points out …)

Thanks to you both for all your comments However, as far as I can tell (in fact what I first tried) included using the ‘shortcut’ first line exactly as it in the instructions (although I don’t specify the shape explicitly). But When I do this I still get errors. I have included below, the code that I used and the error message that follows. Still seems that using F1 filter would be more correct - but this did not work either

Again thanks for any help you could provide

{moderator edit - solution code removed}

you cannot edit this cell


public_tests.convolutional_block_test(convolutional_block)
tf.Tensor(
[[[0. 0. 0. 0.03110444 0. 0.2228643 ]
[0. 0. 0. 0.01448277 0. 0.11220478]]

[[0. 0. 0. 0.00741222 0. 0.18840416]
[0. 0. 0. 0. 0. 0.11712705]]], shape=(2, 2, 6), dtype=float32)

AssertionError Traceback (most recent call last)
Input In [6], in <cell line: 3>()
1 ### you cannot edit this cell
----> 3 public_tests.convolutional_block_test(convolutional_block)

File /tf/W2A1/public_tests.py:111, in convolutional_block_test(target)
108 tf.keras.backend.set_learning_phase(True)
110 B = target(X, f = 2, filters = [2, 4, 6])
→ 111 assert np.allclose(B.numpy(), convolutional_block_output2), “Wrong values when training=True.”
113 print(‘\033[92mAll tests passed!’)

AssertionError: Wrong values when training=True.

You are missing the point about the input to the shortcut layer. Your parameters are correct, but the input is wrong. Draw a picture of the way your “compute graph” connects and then compare that to the picture shown in the notebook. With your version of the code, there is no point to this line of code that was given to you in the template code:

# Save the input value
X_shortcut = X

Please think about the purpose of that line of code. It’s there for an important reason.

Also please note that we are not supposed to share source code on a public thread. There is no real harm done, since I edited the thread to hide the code. But that was the purpose of the DM thread that you already had started with me: to discuss the details of the code in private.