C4W1A1 | Exercise3 conv_foward | AssertionError: Wrong Z mean. Expected: -0.5384027772160062 got: -56.70957026387962

I’m trying to figure out what the problem is… I found the same issues in the community but i didn’t get anything to solve the problem. I think it is fine with the shape and the for loops in my code. Can anyone help me?!

Z's mean =
 8.197763428003048
Z[0,2,1] =
 [-51.13640902  10.93358694 -16.67526948  25.91524569  17.48959664
  61.96334769  15.97168671  21.00441112]
cache_conv[0][1][2][3] =
 [-1.1191154   1.9560789  -0.3264995  -1.34267579]
First Test: Z's mean is incorrect. Expected: 0.5511276474566768 
Your output: 8.197763428003048 

First Test: Z[0,2,1] is incorrect. Expected: [-2.17796037, 8.07171329, -0.5772704, 3.36286738, 4.48113645, -2.89198428, 10.99288867, 3.03171932] 
Your output: [-51.13640902  10.93358694 -16.67526948  25.91524569  17.48959664
  61.96334769  15.97168671  21.00441112] 

---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-218-7e580406a9e8> in <module>
     15 
     16 conv_forward_test_1(z_mean, z_0_2_1, cache_0_1_2_3)
---> 17 conv_forward_test_2(conv_forward)

~/work/release/W1A1/public_tests.py in conv_forward_test_2(target)
    117                              [-0.47552486, -0.16577702, -0.64971742,  1.63138295]])
    118 
--> 119     assert np.isclose(Z_means, expected_Z), f"Wrong Z mean. Expected: {expected_Z} got: {Z_means}"
    120     assert np.allclose(cache_conv[0][1, 2], expected_conv), f"Values in Z are wrong"
    121 

AssertionError: Wrong Z mean. Expected: -0.5384027772160062 got: -56.70957026387962

Please click my name and message your notebook as an attachment.

The most common error here is not handling the “stride” value correctly. Notice that the first test case there has stride = 2. The key point is that the loops here are over the output space and we need to touch each point in the output space and not skip any. The stride happens in the input space, meaning that the stride should not be included in the ranges of the for loops. You use the stride to calculate the vert_start and horiz_start positions in the input space at each iteration.

2 Likes

@unha Thanks for the notebook.

Here are some hints for exercise 3: conv_forward. The brackets are incorrect when computing entries of Z.
Here are the correct steps:

  1. Compute element-wise product of a_slice_prev and weigths.
  2. Sum all elements of the resulting array.
  3. Add bias to this result.

This is your implementation:

  1. Compute element-wise product of a_slice_prev and weigths.
  2. Add bias to this result.
  3. Sum all elements of the resulting array.

When a scalar is added to an array, it’s added to all elements. This has the effect of adding the bias multiple times to the result. I recommend using conv_single_step instead.