Course 4 week 1 exercise 3: Make sure you include stride

Taking the course on coursera-platform.

My code for conv_forward is passing the first but not the second test. It tells me to make sure to include stride in my calculation. The only place I found to include it is in the calculation for n_H and n_W. Do I need to use it somewhere else?

Also, I’m confused as to why a_slice_prev is defined in the innermost loop if it uses all of the channels and not just c. (I’m assuming I need them all because the hint said it was 3-D). Output:

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] First Test: Z’s mean is incorrect. Expected: 0.5511276474566768 Your output: 0.5329033220060434 . Make sure you include stride in your calculation 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: [-0.05723279 0.03991888 -6.24285862 0.53960581 -5.04059676 6.96991358 3.69509379 -0.20955895] Make sure you include stride in your calculation

Those hints about what to look for in your code are very approximate. There are a lot of moving parts in conv_forward and (hence) lots of potential ways to go off the rails. The best suggestion for how to debug is to start by reading this post, which does a great job of explaining what happens in conv_forward in words.

2 Likes

Note that it matters a lot when you are talking about convolutions whether you mean input channels or output channels, right? At each iteration of the innermost loop in conv_forward, you are mapping from a 3D area in the input space (including all the input channels) into a single point (meaning one set of h, w and c values) in the output space.

Of course note that when we get to pool_forward later, it will be a slightly different story. Pooling happens on a “per channel” basis and preserves the input channels.

Thanks, I got both functions working now.

1 Like

That’s excellent news! @mrgransky to the rescue once again. Onward! :nerd_face:

1 Like