Hello.
I am stuck on conv_forward . I get this error messsage:
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)
83 biases = b[ :, :, :, c]
84 biases = biases[:3]
—> 85 Z[i, h, w, c] = conv_single_step(a_slice_prev, weights, biases)
86 # YOUR CODE ENDS HERE
87
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 = np.sum(Z + b).astype(float)
ValueError: operands could not be broadcast together with shapes (2,3,4) (3,3,4)
Could please help me ?
Thank you.
Here’s another thread with a similar problem that goes through some things to check.
Thanks, I already solved it. I had trouble with the use of slicing arrays in numpy.
My second test is passed, but first test is failing. I have checked the shape and a_slice_prev but still unable to figure out the issue. Please help
Please realize that we can’t see your notebooks. So you need to give us a bit more context here in order for us to know what to say. The best way to start is to show (by “copy/paste” or screenshot) the actual full output you are getting including the exception trace (if any).
I am also stuck with the dimension error, don’t know where to correct. Any one please explain?
The clue is that you pass the first test (the one shown in the notebook) which has padding = 1. But then you fail in the second test (the one from public_tests.py
). There the padding is never 1, but they have three different cases with p = 3, p = 0 or p = 6. It looks like you are stepping off the end of the “input” space in the w dimension. So look at how you are handling the padding: you must be hard-coding it to 1 in the place where you compute the size of A_prev_pad
, but then not when you run the actual loops.
Hi @paulinpaloalto,
Thank you. i corrected the shape error but now i am getting wrong value. Here is my code:
{moderator edit - solution code removed}
Here is the output:
can you please through some ideas on what could be wrong ?
thanks
The way you are handling the stride is incorrect. By using it as the “step” on the loop ranges, that means you will skip positions in the output space. It is supposed to happen only in the input space, right? The h and w loop values must be incremented by 1 each time, then you need to compute where that “maps” to in the input space. If that point doesn’t make sense, I think you should go back to the lectures and watch Prof Ng’s explanation of how the stride works. Your code does not implement what he says.
Thank you so much for the finding. I corrected it.
