C4, Week 1, conv_forward

I am having trouble with slicing the array. Can anyone explain to me how its done. I have been trying to do it but it keeps showing this error.

The vert and horiz parameters are only used for a_slice_prev.
They aren’t used for weights and biases.

The weights and biases only use slicing with ‘c’ as the last parameter.

Also note that there must be a problem with your vert/horiz start/end values if you are getting 0 as the first two dimensions of a_slice_prev.

1 Like

thank you, I was able to fix it for the vert_start and vert_end but I am still having trouble with the horiz_start and horiz_end. After trying to fix it I am getting 3 and 4 as the first two dimensions.
Can you help me with that?

i instrumented my conv_forward code to print the shapes of everything. Here’s what I get when I run the test cell for conv_forward:

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]
New dimensions = 9 by 11
Shape Z = (2, 9, 11, 8)
Shape A_prev_pad = (2, 11, 13, 4)
a_prev_pad shape = (11, 13, 4)
Z[0,0,0,0] = -1.2238796505752447
a_prev_pad shape = (11, 13, 4)
Z[1,8,10,7] = -0.47458986707940803
New dimensions = 2 by 3
Shape Z = (2, 2, 3, 8)
Shape A_prev_pad = (2, 5, 7, 4)
a_prev_pad shape = (5, 7, 4)
Z[0,0,0,0] = 3.14880664541713
a_prev_pad shape = (5, 7, 4)
Z[1,1,2,7] = 1.0956417259542868
New dimensions = 13 by 15
Shape Z = (2, 13, 15, 8)
Shape A_prev_pad = (2, 17, 19, 4)
a_prev_pad shape = (17, 19, 4)
Z[0,0,0,0] = -0.5096687406137471
a_prev_pad shape = (17, 19, 4)
Z[1,12,14,7] = -0.3247422640409677
(2, 13, 15, 8)
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
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
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
 All tests passed.

Notice that 3 x 4 are the output h x w dimensions for the first test case, but the a_prev_pad dimensions include the padding and are based on the input dimensions. Of course the a_slice_prev dimensions need to match the first 3 dimensions of W, so they will be 3 x 3 x 4.

1 Like