C4_W1_Exercise 3_Error in conv_forward func

Hello !

I am getting a following error:
---------------------------------------------------------------------------
IndexError 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)
93
94 for c in range(n_C):
—> 95 a_slice_prev = A_prev_pad[vert_start:vert_end, horiz_start:horiz_end, :]
96 weights = W[:, :, :, c]
97 biases = b[:, :, :, c]

IndexError: too many indices for array.

The funny thing is that I tried to debug and printed out intermediate values, it passes 96 times through all loops, therefore getting 96 values for output matrix Z. I guess this is a correct number as the output matrix size should be 3x4 and additional 8 filters so 3x4x8 = 96

Please help to figure out where I could have a mistake.
Thanks in advance

You have used A_prev_pad instead of the array which contains just the i’th training example. You have created that array in the beginning of the loop.

Hello @RolandSherwin,
true, my fault was that I kept the same name for both A and A[i]… thank you!

Now I have 192 passes so for 2 training examples.
And I have this message:

Error: Wrong output for variable in position 0.
2 Tests passed
1 Tests failed

In position 0 I have the following:
Z[i, h, w, c] = Z[(0, 0, 0, 0)] = -2.651123629553914

I get the same output as well, Z[ 0 0 0 0 ]: -2.651123629553914 maybe there is an issue somewhere else. Can you share me more of your code?

Here is the full error message:


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_))

Does this help ?

Can you send that entire function instead? The error message doesn’t help much…

Hi Roland,
I’m getting the same error, here. I also got Z = -2.651123629553914.
Could I paste my function for feedback?

Thank you!

Make sure to include stride in your code. Also make sure that the vert_start and horiz_start has to jump certain cells (refer the image in the prev block) depending on the value of stride.

I have worked the stride into the vert start and horiz start variables and am not progressing in this error.

Can you share your code?

Hi sjo42,

Have another look at the formula given to calculate the output shape (and don’t forget to set your loop range correctly). Good luck!

Hi Viktoriia,

Did you loop over the full batch of training examples?

thank you for your help!

You’re welcome. Could you remove your code? Many thanks and good luck with the rest of the course!

I am also facing the similar error sir. I am not able to figure it out where is my mistake. Could You please help me sir? I considered stride and shapes also correctly.

Hi kumarcvt,

Do you loop over the full batch of training examples?

Yes sir. I looped over the all training examples.

Hi kumarcvt,

If strides, shapes, and batch are all fine, it’s hard to tell what could be the problem without looking at your code. Can you send me a direct message with your code? Then I can have a look.

Hi,
I have the same problem. This is my code.

{moderator edit - solution code removed}

1 Like

Hi Sathwik,

Think about the stride you are using. How can you include it into your loop?

1 Like