Getting this error

Z’s mean =
-0.721419291163663
Z[0,2,1] =
[-1.39881282 -2.9097526 -4.96371197 -3.47321226 -2.17796037 -2.17796037
-2.17796037 -2.17796037]
cache_conv[0][1][2][3] =
[-1.1191154 1.9560789 -0.3264995 -1.34267579]
Error: Wrong output for variable in position 0.
2 Tests passed
1 Tests failed

AssertionError 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)
382 ]
383
→ 384 multiple_test(test_cases, target)
385
386

~/work/release/W1A1/test_utils.py in multiple_test(test_cases, target)
151 print(’\033[91m’, len(test_cases) - success, " Tests failed")
152 raise AssertionError(
→ 153 “Not all tests were passed for {}. Check your equations and avoid using global variables inside the function.”.format(target.name))

AssertionError: Not all tests were passed for conv_forward. Check your equations and avoid using global variables inside the function.

Can someone help?

1 Like

my code is:

(Code has been removed by staff as sharing it publicly is against the honour code)

There are several errors here. Note that the inner loop is over the output channels: the c value is one of the output channels, not a range of the output channels. And maybe more critically not anything to do with the input channels, right? Note that when you slice the weights, you are slicing the input channels, instead of selecting the appropriate output channel. Also you are slicing the bias value incorrectly and always using the bias for output channel zero. You are making the analogous mistake in slicing a_slice_prev that I described with the weights: there you just need all the input channels, right?

I’m not sure that is everything, but I think the first step is to read carefully through the instructions to get a clearer mental picture of how all this is supposed to work. The way to think about this is that for each output channel, you are processing all the input channels at the given (h,w) position. That means that the filter for each output channel has the shape (f, f, n_C_prev). That is why the shape of W is (f, f, n_C_prev, n_C).

Also please note that while it sure makes it easier to debug when we can see the source code, we’re not supposed to leave the source code sitting visible on the forums. Once you have this solved, please do us a favor and edit your post to remove your source code. Thanks!

1 Like

Hi Paul Sir,
Thank you for taking the time to reply.

I am writing my understanding, please do correct me if I am wrong.

  • Image of dimensions (m,n_H_prev,n_W_prev,n_C_prev) is convolved with filter (f,f,n_C_prev, n_C) to get one output
  • We then stack these outputs to get the output

Removed Code

I am still not able to figure the vert_start/horiz_start and end.

Hope the changes I made in the code is correct?

And surely will be deleting the code after I have solved this. Thanks,

It’s closer, but there are still a couple of mistakes:

You need to take the stride into account on your calculations for horiz_start and vert_start.

You’re looping over the input channels, but you should be looping over the output channels, right? Just as the h and w loops are over the output volumes, so is the channel loop: for each output channel, you apply the full f x f x n_C_prev filter to the input at each strided position.

1 Like

yes sir, got it. I have passed the test

1 Like

Hello! I got the same error as the original post but wasn’t able to fix it yet.
You mentioned using stride for calculating the starting points, but the way I would start looking at this is by changing the step size in the for loop. Could you help me see the correct approach?

1 Like

The right way to look at the convolution process is to view everything in terms of the output of a given layer. All the loops are over the output volume, for both the height and width dimensions as well as the channels, as I was saying earlier on this thread. Then within the logic of the loops, you have to keep track of where you are in the input space. You start at 0 in the input space and then step through according to the stride value and the size of the filter. If you have trouble visualizing that, it might be worth going back and watching the lectures in Week 1 of Course 4 again with what I said above in mind. E.g the Strided Convolutions Lecture.

2 Likes