C4W1A1 Exercise 3 - conv_forward()

Hello,
I am trying to finish C4W1 Exercice3 - conv_forward(). I passed 2 tests but failed one and had the error message: “Wrong output for variable in position 0”. Any hint on how to check the initial position?
Regards

Please post your results from the test case cell, where it displays your Z and cache values.

There are a lot of potential causes. Your a_slice_prev, weights, or biases variables could have the wrong values.

Thank you @TMosh for your message. Here are the results.
I keep reviewing my code, but any hint will be very much welcome!

Z’s mean =0.28648854269868845
Z[0,2,1] =
[0. 0. 0. 0. 0. 0. 0. 0.]
cache_conv[0][1][2][3] =
[-1.1191154 1.9560789 -0.3264995 -1.34267579]
(2, 13, 15, 8)
Error: Wrong output for variable in position 0.
2 Tests passed
1 Tests failed

AssertionError Traceback (most recent call last)
in
11 print(“cache_conv[0][1][2][3] =\n”, cache_conv[0][1][2][3])
12
—> 13 conv_forward_test(conv_forward)

~/work/release/W1A1/public_tests.py in conv_forward_test(target)
118 ]
119
→ 120 multiple_test(test_cases, target)
121
122

~/work/release/W1A1/test_utils.py in multiple_test(test_cases, target)
151 print(’\033[91m’, len(test_cases) - success, " Tests failed")
152 raise AssertionError(
→ 153 “Not all tests were passed for {}. Check your equations and avoid using global variables inside the function.”.format(target.name))

AssertionError: Not all tests were passed for conv_forward. Check your equations and avoid using global variables inside the function.

The Z values should not be all-zeros. So there is certainly an error in your code for computing either a_slice_prev, weights, or biases.

{edited my reply to remove some stuff}

For others who read this thread:
Do not use “stride” as the iterator in a for-loop.

Please don’t post your code on the forums. The course Honor Code doesn’t allow it.

You really shouldn’t direct your posts to an individual mentor, since there are quite a few who could help you.

Your coding for a_prev_pad is incorrect. It should slice A_prev_pad using ‘i’ as the first dimension.

The stride is used only in setting the start and end indices. For the start index you should multiply h or w by stride. And then the end index adds f to the start index.

The slicing for weights and biases use the same pattern; a bunch of colons and then slice using ‘c’.

1 Like

And the slicing for a_slice_prev should use the vert start and end, then the horiz start and end, and then a colon.