DL CNN Week 1 homework 1

I have worked on the conv_forward(A_prev, W, b, hparameters) function. I have an answer coming out, but test 1 indicates that it is wrong. I have tried every which way to examine the bias, the weights the slicing, but they all appear to be correct. I used the test that was successful against the conv_single_step() method and verified that the conv_forward(A_prev, W, b, hparameters) gets the correct answer still with this test:

np.random.seed(1)
a_slice_prev = np.random.randn(1, 4, 4, 3)
W = np.random.randn(4, 4, 3, 1)
W1 = np.zeros((4,4,3,2))
W1[:,:,:,0] = W[:,:,:,0]
W1[:,:,:,1] = W[:,:,:,0]
b = np.random.randn(1, 1, 1, 1)
b1 = np.zeros((1,1,1,2))
b1[:,:,:,0] = b[:,:,:,0]
b1[:,:,:,1] = b[:,:,:,0]
hparameters = {“pad” : 0,
“stride”: 1}
Z,cache = conv_forward(a_slice_prev, W1, b1, hparameters)
print(“Z =”, Z[0,0,0])

assert (type(Z[0,0,0,0]) == np.float64), “You must cast the output to numpy float 64”
assert np.isclose(Z[0,0,0,0], -6.999089450680221), “Wrong value”

For test one of the conv_forward(A_prev, W, b, hparameters) method testing though I keep getting:

First Test: Z’s mean is incorrect. Expected: 0.5511276474566768
Your output: 0.5329033220060434

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]

Any ideas?

Hello @Kirk_Walker! We appreciate your post, but it is in the incorrect category. To ensure that your question receives a prompt and accurate response, I suggest that you edit your post by clicking the pencil icon located next to the title and move it to the relevant course category, as shown in the attached image below. Our mentors will be happy to assist you.

As your question belongs to the DLS 4 course, kindly move it there. Although I am a mentor for DLS, this topic is not my area of expertise. But our expert mentors will assist you.

Best,
Saif.

I’ve moved it so it might get a mentor reply earlier.

Notice that the first test case for conv_forward has stride = 2, but the test case you constructed that you pass uses stride = 1. Handling the stride correctly is one of the things that commonly trips people up here. The key thing to remember is that all the loops here are over the output space and we must touch every position there even when stride > 1. The striding happens in the input space and is reflected in the vert_start and horiz_start values that we need to calculate.