Exercise 3 - conv_forward error problem

I am stuck in this homework. I get this error:


ValueError Traceback (most recent call last)
in
6 “stride”: 2}
7
----> 8 Z, cache_conv = conv_forward(A_prev, W, b, hparameters)
9 print(“Z’s mean =\n”, np.mean(Z))
10 print(“Z[0,2,1] =\n”, Z[0, 2, 1])

in conv_forward(A_prev, W, b, hparameters)
97 weights = W[:, :, :, c]
98 biases = b[:,:,:, c]
—> 99 Z[i, h, w, c] = conv_single_step(a_slice_prev, weights, biases)
100
101

in conv_single_step(a_slice_prev, W, b)
23 # Z = None
24 # YOUR CODE STARTS HERE
—> 25 s = a_slice_prev * W
26 # Sum over all entries of the volume s.
27 Z = np.sum(s) + np.float(b)

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

This is my code, can somebody help me?

def conv_forward(A_prev, W, b, hparameters):
    
    # YOUR CODE STARTS HERE
{mentor edit: code removed - not allowed by the Honor Code
    # YOUR CODE ENDS HERE
    
    # Save information in "cache" for the backprop
    cache = (A_prev, W, b, hparameters)
    
    return Z, cache

Hello @steven123,

First of all, I have moved your post to the right place: #deep-learning-specialization:dls-course-4.

You have made a mistake when extracting

a_slice_prev = A_prev_pad[vert_start:vert_end, horiz_start:horiz_end,:]

What is the difference between A_prev_pad and a_prev_pad and which one should you use in this case?

1 Like