Course4-week1-prog1

Just confirming before I spend more time (already spent 5+ hrs) on this:

  • making sure there is no error in conv_forward_test():

A_prev.shape = (2, 5, 7, 4)
f = 3
pad = 1
stride = 3
W.shape = (3, 3, 4, 8)
b.shape = (1, 1, 1, 8)

n_H should be floor((5-3+2)/3) +1, which is 2
Not 9 as expected


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)
68 Z_shape = Z.shape
69 assert Z_shape[0] == A_prev.shape[0], f"m is wrong. Current: {Z_shape[0]}. Expected: {A_prev.shape[0]}"
—> 70 assert Z_shape[1] == 9, f"n_H is wrong. Current: {Z_shape[1]}. Expected: 9"
71 assert Z_shape[2] == 11, f"n_W is wrong. Current: {Z_shape[2]}. Expected: 11"
72 assert Z_shape[3] == W.shape[3], f"n_C is wrong. Current: {Z_shape[3]}. Expected: {W.shape[3]}"

AssertionError: n_H is wrong. Current: 2. Expected: 9

**** please let me know if I am wrong.

Your value for stride is wrong, should be 2 (depending on which test case you’re considering).

And (for that same test case):
n_H is 3
n_W is 4.

Thank you. The values (stride, pad, f, W, bias, and A_prev) are NOT set by me. I think this is the 8th filter in the first programming assignment coming from the grader code: conv_forward_test() from public_tests.py

I just printed the values so I can ask the question. So, we do agree that for the given A-Prev, pad, stride, and f, the expected n_H is wrong? This would mean a bug in the grader code.

No, we are not in agreement. The test case is correct.

Could you elaborate please:

You said:
“And:
n_H is 3
n_W is 4.”

The assertion is expecting:
70 assert Z_shape[1] == 9, f"n_H is wrong. Current: {Z_shape[1]}. Expected: 9"
71 assert Z_shape[2] == 11, f"n_W is wrong. Current: {Z_shape[2]}. Expected: 11"

Also, re: your comment: “Your value for stride is wrong, should be 2.”
Please note that the test taker is not setting the stride. The stride I printed is what was passed on from the testing script.

Stride is 2. It is set here:
image

Or, if you’re looking at the test that is defined in public_tests.py, then you have:
image

Where pad is 3 and stride is 1.

Your stated it backwards in your OP.

Thank you, that absolutely makes sense and it was the source of my error. I was strictly going after the descriptor of the function conv_forward:

hparameters – python dictionary containing “stride” and “pad”

and took that ordering for granted.

Thank you for the elaboration, very helpful.