Error with conv_forward_test()

I am getting with error on function conv_forward()

Z's mean =
 0.3519500704507587
Z[0,2,1] =
 [ -3.01280755  -2.90226517  -8.34171936  -5.26220853   5.6630696
   1.08704033   2.20430705 -10.73218294]
cache_conv[0][1][2][3] =
 [-1.1191154   1.9560789  -0.3264995  -1.34267579]
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-68-182241fd5e53> in <module>
     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)
    296     assert Z_shape[3] == W.shape[3], f"n_C is wrong. Current: {Z_shape[3]}.  Expected: {W.shape[3]}"
    297 
--> 298     Z, cache_conv = target(A_prev, W, b, {"pad" : 0, "stride": 2})
    299     assert(Z.shape == (2, 2, 3, 8)), "Wrong shape. Don't hard code the pad and stride values in the function"
    300 

<ipython-input-67-7dadac1fa933> in conv_forward(A_prev, W, b, hparameters)
    103                     biases = b[:,:, :, c]
    104 
--> 105                     Z[i, h, w, c] = conv_single_step(a_slice_prev, weights, biases)
    106 
    107     # YOUR CODE ENDS HERE

<ipython-input-4-b2ecf972598e> in conv_single_step(a_slice_prev, W, b)
     23     # Z = None
     24     # YOUR CODE STARTS HERE
---> 25     s = a_slice_prev *  W
     26     Z = np.sum(s)
     27     Z = Z + float(b)

ValueError: operands could not be broadcast together with shapes (0,3,4) (3,3,4) 

I am not understanding how I am getting this error on function conv_single_step(a_slice_prev, W, b) , if it was previously working properly…

1 Like

Hi Gloria,

Excuses for the belated reply. Have you been able to resolve this issue?

Hi!
In the end, yes. The error was related to the wrong stride index during for loop.

1 Like

Happy to hear it! Good luck with the rest of the course!