Hello, I think I got my code right but keep getting an error at the end of the big for loop. I believe the slice dimension is 3,3,4 but I don’t understand where the 2,3,4 came from? I am pretty sure I did the for loops right with the strides and everything
I believe your shapes for “a_slice_prev” and “weights” are incorrect.
Your slicing of the “W” variable looks incorrect - you should have some colons and commas, not three-dots.
I’ve fixed the W variable but am still getting the same error.
I’m not sure how my shapes for a_slice_prev is incorrect, since wouldn’t it just be:
a_slice_prev = A_prev_pad[vert_start:vert_end,horiz_start:horiz_end,c]
That’s not correct. The ‘c’ as the last parameter means you aren’t slicing.
That’s a good point. I think you should also look at your handling of the stride. The fact that you basically ran off the end A_prev_pad in the h dimension and ended up with 2 instead of 3 there indicates that your vert_start value is incorrect. I think one way to get that type of error is to include the stride in the “range” of the h and w loops. That’s a mistake, but you don’t notice until you try a stride value > 1. The way to think of this is that the loops are over the output space, right? Meaning that you need to touch each position and not skip any. The stride happens in the input space, not the output space.
Facing same issue but not sure where it is going wrong.
ValueError Traceback (most recent call last)
in
11 print(“cache_conv[0][1][2][3] =\n”, cache_conv[0][1][2][3])
12
—> 13 conv_forward_test(conv_forward)
~/work/release/W1A1/public_tests.py in conv_forward_test(target)
61 b = np.random.randn(1, 1, 1, 8)
62
—> 63 Z, cache_conv = target(A_prev, W, b, {“pad” : 3, “stride”: 1})
64 Z_shape = Z.shape
65 assert Z_shape[0] == A_prev.shape[0], f"m is wrong. Current: {Z_shape[0]}. Expected: {A_prev.shape[0]}"
in conv_forward(A_prev, W, b, hparameters)
82 weights = W[:,:,:, c]
83 biases = b[:,:,:,c]
—> 84 Z[i, h, w, c] = conv_single_step(a_slice_prev, weights, biases)
85
86 # YOUR CODE ENDS HERE
in conv_single_step(a_slice_prev, W, b)
23 # Z = None
24 # YOUR CODE STARTS HERE
—> 25 s = np.multiply(a_slice_prev, W)
26 Z = np.sum(s)
27 Z = Z + float(b)
ValueError: operands could not be broadcast together with shapes (3,2,4) (3,3,4)
The bug is not in conv_single_step, but in conv_forward. It sounds like you have made some variation of the same error that was discussed earlier on this thread: putting the stride in the range specifier of the loop. Please have a look at this earlier reply and see if it sheds any light.