W2A1/Residual_Networks.ipynb | ResNet50 function

W2A1/Residual_Networks.ipynb

First identity_block() call in Stage 2 section returns None

# Stage 2
X = convolutional_block(X, f=3, filters = [64, 64, 256], s=1)
X = identity_block(X, 3, [64, 64, 256])
X = identity_block(X, 3, [64, 64, 256])  
### START CODE HERE

Note, that this is before ### START CODE HERE section.
Please advise.

Have you actually run the cell that defines the identity_model?

Yes, I did. Otherwise I would expect an error telling me that identity_block is undefined. Currently, from

Stage 2

X = convolutional_block(X, f = 3, filters = [64, 64, 256], s = 1)
print(f"Stage 2: 0: X={X}")
X = identity_block(X, 3, [64, 64, 256])
print(f"Stage 2: 1: X={X}")
X = identity_block(X, 3, [64, 64, 256])
print(f"Stage 2: 2: X={X}")

I am getting:

Stage 2: 0: X=KerasTensor(type_spec=TensorSpec(shape=(None, 15, 15, 256), dtype=tf.float32, name=None), name=‘activation_13/Relu:0’, description=“created by layer ‘activation_13’”)
Stage 2: 1: X=None

Assuming you did not modify any of the code in ResNet50() before the “START CODE HERE” banner:

I suspect there could be an error in your convolutional_block() function.

Assuming you did not modify any of the code in ResNet50() before the “START CODE HERE” banner:

I just added these debugging print statements before START CODE HERE, and for whatever it is worth I am getting “All tests passed!” from public_tests.convolutional_block_test(convolutional_block)

Passing the tests in the notebook is a good sign, but it doesn’t prove your code is perfect.

Here’s a topical observation.

The notebook for this assignment was just updated today, to add another test case for the specific situation of using the wrong parameter for the strides argument in the convolutional_block() “shortcut” path.

This specific error is not caught by the previous unit test, but it causes errors in the ResNet50() tests.

What are you using for the stride parameter?

You mean in convolutional_block() function?

As per instructions above the function body i.e. “Shortcut path: The CONV2D has 𝐹3 filters of shape (1,1) and a stride of (s,s)…”

What can I do here? How to debug this problem?

Update for those who find this thread later:
In ResNet50():

  • Be sure you use the correct filter sizes.
  • For 2D Average pooling, do not specify a shape. Use the code given by the comment.