Week 1 Assignment 1 conv_forward issue

Hi :slight_smile:

I’ve got an issue with writing the conv_forward function, i.e. I’m not getting the right output values. I’ve been going through some of the posts here and my dimensions are correct, so that’s not the issue. I’d be grateful if someone could give me a hint!

{moderator edit - solution code removed}

and getting the following error…

Z's mean =
 0.5329033220060434
Z[0,2,1] =
 [-0.05723279  0.03991888 -6.24285862  0.53960581 -5.04059676  6.96991358
  3.69509379 -0.20955895]
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)
<ipython-input-7-182241fd5e53> in <module>
     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.
1 Like

you have a problem with calculating the corners (vert_start, vert_end, horiz_start, horiz_end)
your code does not take the stride quantity into consideration.
you should have included stride in calculating those quantities to control the stepping

3 Likes

Exactly. As @Muhammad-Elmallah says, the stride needs to be included in the calculations for vert_start and horiz_start. Now that we have a solution, I will go ahead and remove your source code from your original post.

Thanks you two, that did it! :slight_smile:

1 Like

Indentation matters in python: it is part of the syntax to define what would be called “blocks” in a language like c, C++, Java or JavaScript. The way you have indented your code, the lines that set weights, biases and Z are not part of the nested for loops. They will be executed only once after all the loops finish.

Once you get this to work, please edit your post to remove the screenshot of the code. Thanks!

thankyou so much , solved the problem of indentation.

1 Like