Exercise 3 - conv_forward - Assertion error

I’ve been stuck on this for a couple of days and can’t seem to get it sorted out. This is the error I’m seeing. Any ideas?

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

— removing code —

You have neglected to take the stride into account when you calculate the position in the input space.

Please note that we don’t want to leave solution source code sitting around in the forums, so please do us a favor and edit your post to remove the source code once you’ve finished debugging this. It’s a violation to put it there in the first place, but I gotta say it sure helps to debug when you can see the code . Thanks!

1 Like

Thanks Paul! I’ll give it another go with Stride in mind.

Removing code from post.

I incorporated stride, but the values are off somewhere. Error below:

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

Does my range function look ok? I used stride value for the step. I did the same thing for the horizontal loop, but something still seems off.

for h in range(0, n_H, stride): # loop over vertical axis of the output volume
# Find the vertical start and end of the current “slice” (≈2 lines)
vert_start = h
vert_end = h + f

Sorry, but that’s not the right way to incorporate the stride. The point is that the stride affects the position in the input space, not the output space, right? Your implementation is skipping areas in the output space. As you already discovered, that does not turn out well. In other words, you need an output value for every value of h between 0 and n_H or w between 0 and n_W. Your code is skipping in the output space. The question is where is the input from for the corresponding output position.

Thank you Paul! I multiplied start and stop values by stride and that did the trick!

JB

1 Like

Cool! That sounds like the ticket. Glad to hear that you found the solution.