C4 W1 A1: Error in conv_forward and pool_forward

Here are the codes and errors. I looked through the other threads as well. I believe there is something very strange and unusual happening here.

Moderator Edit: Solution Code Removed

Moderator Edit: Solution Code Removed

Please help.

First, sharing your code is not allowed by the community code of conduct. So avoid sharing it.

I found a couple of mistakes in your code. Your for loop for n_H and n_W will only work when stride is 1. You have given that loop over the vertical axis/horizontal axis of the output volume. Did they mention skipping some axis in the range of loop? No, the skipping will be done in the next calculation, not in the range of loop. But you are making it complex by using stride as a step in it.

Your vert_start , vert_end , horiz_start , and horiz_end are also wrong. You need to see this post.

Woah! Thank you so much, you’re a genius. I fixed the for loops and the start, end variables and it worked perfectly.

Could you please explain how involving stride in the start, end variables would be different from involving it as a step in the for loops? Wouldn’t they both have the same effect?

Thanks again for pointing out the bug.

Let’s say n_C is 3 and stride is 2. Please try both methods with paper and pen and you will see the difference.

No, they are not the same. The key point to understand here is that the loops are over the output space (Z) and you must touch each position in the output space. The striding happens in the input space, which is A_prev_pad, right? Look at the computation and see how vert_start and vert_end are used versus how the h value is used.