C2W1: Assignment1 Exercise3: Assertion Error!

On the 3rd exercise conv_forward of Assignment 1, I am getting an assertion error. Here is my output :

I am not sure what I am missing, a little hint will be well appreciated. if you need my source code to process things I can dm you (mentor only) privately.

Note that the single Z value that the test prints is all zeros. That is pretty suspicious. Here’s what I get from that first test (with some extra prints to show the dimensions of various objects):

New dimensions = 3 by 4
Shape Z = (2, 3, 4, 8)
Shape A_prev_pad = (2, 7, 9, 4)
a_prev_pad shape = (7, 9, 4)
Z[0,0,0,0] = -2.651123629553914
a_prev_pad shape = (7, 9, 4)
Z[1,2,3,7] = 0.4427056509973153
Z's mean =
 0.5511276474566768
Z[0,2,1] =
 [-2.17796037  8.07171329 -0.5772704   3.36286738  4.48113645 -2.89198428
 10.99288867  3.03171932]
cache_conv[0][1][2][3] =
 [-1.1191154   1.9560789  -0.3264995  -1.34267579]

You’ll notice that my Z[0,2,1] is not all zeros. This suggests that you are making some mistake in how your “for” loops work. One important thing to realize is that the loops are over the output space, right? We have 4 total dimensions here and we must touch every element of the output space. But the stride values apply to the input space: that’s where we may skip things. My guess is that you are misapplying the “stride” somehow to the output space instead of the input space.

Hey @paulinpaloalto I tried to get the shape of those matrices, and their output are as follows.

shape of Z (2, 3, 4, 8)
shape of A_prev_pad (2, 7, 9, 4)
shape of a_prev_pad (7, 9, 4)
shape of a_slice_prev (3, 3, 4)

Z[0,0,0,0] 0.0
Z[1,2,3,7] 0.4427056509973153
Z's mean =
 0.5151827378782476
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]

shape of Z (2, 9, 11, 8)
shape of A_prev_pad (2, 11, 13, 4)
shape of a_prev_pad (11, 13, 4)
shape of a_slice_prev (3, 3, 4)

Z[0,0,0,0] 0.0
Z[1,2,3,7] -0.19892396465345275

shape of Z (2, 2, 3, 8)
shape of A_prev_pad (2, 5, 7, 4)
shape of a_prev_pad (5, 7, 4)
shape of a_slice_prev (3, 3, 4)

also about your stride implementation concern, I multiplied it with h and w like this

vert_start = h*stride
horiz_start = w*stride

I don’t know if I implemented this right?

Interesting. I’m having a hard time coming up with a theory for what could produce your results. Notice that your Z[0,0,0,0] is consistently 0.0 everywhere, but your Z[1,2,3,7] is actually correct on the first test. Notice that I’m not always printing 1,2,3,7: I’m using the max of all the possible indices in the particular case. So we can’t see whether those numbers are correct in your other cases.

The way you show the stride being used looks correct. So I think we’re down to something being wrong with the way the h and w and c values are computed in your “for” statements. Are you sure you are just stepping through every value in the range and not doing “striding” in your loop “range” expression? Although even with that type of mistake, I’d expect your loops to hit the [0,0,0,0] case. Just to be clear, Z is initialized to zeros, so what I’m saying is that your loops are simply skipping a bunch of positions in the output space and thus leaving the values as the initial zeros.