ResNet C4 W2 A1- Ex2 convolutional_block. Error: AssertionError: Wrong values when training=False

Hello there,

I think I am joining the club of those participants who get this same error. I rechecked the solutions but none applied to me.

In the assignment, I have the following values:

2nd Component
Filter F2, kernel_size = f, strides = 1, padding = same

3rd Component
Filter F3, kernel_size = 1, strides = 1, padding = valid

Shortcut Component
Filter F3, kernel_size = 1, strides = s, padding = valid

Initialization appended to all three lines above
kernel_initializer = initializer(seed=0) for (X), which will use the glorot_uniform initializer as default.

I truly see no error in the code, but obviously, because the grader does not mark this as successful, there most be one. Could anybody give any pointers?

Thank you!

AssertionError                            Traceback (most recent call last)
<ipython-input-6-869d2d1d4c16> in <module>
     12 assert type(A) == EagerTensor, "Use only tensorflow and keras functions"
     13 assert tuple(tf.shape(A).numpy()) == (3, 2, 2, 6), "Wrong shape."
---> 14 assert np.allclose(A.numpy(), convolutional_block_output1), "Wrong values when training=False."
     15 print(A[0])

AssertionError: Wrong values when training=False.

The key to the “wrong values when training=False” error is what you’re doing in the Batch Normalization layers - not the Conv2D layers.

Hi @TMosh , thanks for your reply.

According to the exercise, all three components plus the shortcut use the exact same Batch Normalization. Thus, I have reused the line of code given by the assignment.

I rechecked and the code is exactly the same, which seems correct:

  • ReLu layer applied to components 1 and 2 only (plus to final step)
  • Batch Normalization applied to the channel axis (axis = 3)

Quite frankly, there is no much that could go wrong there. And yet.

Any pointers would be greatly appreciated.


You need to include the argument “training=training” in all of the batch normalization layers.

It’s in the instructions:

Hi @TMosh , that is how I have it already:

BatchNormalization(axis = 3)(X, training=training)

It does not work for me. Could it be then a problem with the grader then?

The other popular mistake is to use the wrong input value for the “shortcut” layers.


No, it’s not a problem with the grader.

Great @paulinpaloalto , that makes total sense and now the problem is fixed. Thank you!

Glad to hear you were able to find the solution. The written instructions for this section are not very explicit about the way the shortcut layers are intended to work, but it’s clearly expressed in the diagrams. So I guess it’s a classic case of a picture being worth more than words! :grin: The shortcuts are kind of a big deal here.


Could you please make it a little bit more clear? I got stuck with this for long time.
Base on my understanding, the input of Shortcut layer should be X_shortcut as it was assigned to be = X at the beginning.
Is it right?
X_shortcut = Conv2D(filters = F3, kernel_size = 1, strides = (s, s), padding=‘valid’, kernel_initializer = initializer(seed=0))(X_shortcut)
X_shortcut =BatchNormalization(axis = 3)(X_shortcut, training=True)
Thank you


Yes, that’s correct. But note that it is a mistake to “hard-code” the value of the training parameter to be True on the BatchNorm call. That will not end well. Just use the value of that parameter that is passed in to the function.

They give you a worked example of that the BatchNorm call should look like earlier. Yours should look the same other than using a different input X value.


I did make it, thank you @paulinpaloalto

Have the same problem. But weirdly only on my M1 Mac. Anyone an idea? The grader seems ok.

If you are running locally, then any differences are probably the result of “versionitis”. Everything mutates really quickly in this space.

Yes, I’m afraid so. The rest is working OK. And the grader was satisfied. So I have te learn with it.

We do not have “official” instructions for how to duplicate the course environment locally, but here’s a great thread put together by a fellow student with lots of valuable information. The main “take away” is that it’s not a simple process.

Thanks! Extra complicating factor is my M1 processor. But most things are possible.

Yes, I just upgraded to an M1 about a month ago also. A lot of the software packages aren’t yet available for the M1 cpu, as I’m sure you are also finding. I’m sure they will eventually catch up. The one that was the biggest hindrance to me so far is that VirtualBox is not available for M1. :cry: Of course now that I think about it \epsilon more, that may not be so easy if the VMs you are running also assume x86 instruction set. :scream_cat: So maybe I need to keep my older x86 Mac around for a while longer.

Hey @paulinpaloalto I have used the correct inputs for the shortcut block as well, but i appear to get the same error.
Despite using the traing=training and the shortcut inputs correctly. I dont see what else is wrong here.