Week 1 programming 1 conv_backward

I got this error…Please help…the part where it shows syntax error is already given in the hint.So how come it’s wrong?

File “”, line 84
A_prev_pad = zero_pad(A_prev, pad)
^
SyntaxError: invalid syntax

TypeError Traceback (most recent call last)
in
10
11 # Test conv_backward
—> 12 dA, dW, db = conv_backward(Z, cache_conv)
13
14 print(“dA_mean =”, np.mean(dA))

in conv_backward(dZ, cache)
67 # dA_prev[i, :, :, :] = None
68 # YOUR CODE STARTS HERE
—> 69 (A_prev, W, b, hparameters) = None
70
71 (m, n_H_prev, n_W_prev, n_C_prev) = None

TypeError: cannot unpack non-iterable NoneType object

You need to replace None with the correct expression that will unpack to those 4 variables. Those hint statements are guides to expected code, but not meant to be copied as-is.

2 Likes

I have not assigned anything as None. The error says invalid syntax. As I can’t post code I’am posting the hint part.

The marked part is already shown. I wrote it as it is. But it says syntax error at A_prev_pad.

I restarted the kernel. The same error at same position. But trace back error changed to

NameError Traceback (most recent call last)
in
10
11 # Test conv_backward
—> 12 dA, dW, db = conv_backward(Z, cache_conv)
13
14 print(“dA_mean =”, np.mean(dA))

NameError: name ‘conv_backward’ is not defined

That error just means that you need to rerun all the earlier cells in the notebook every time you restart the kernel or close and reopen the notebook. Try “Cell → Run All Above”.

But for the earlier error that this thread is about, you are misunderstanding what is intended here. You need to replace the “None” on the RHS of that assignment statement. The statement as written is not complete: it is the “template” code they are giving you. You need to fill in some code everywhere that you see “None”.

I have not assigned anything as None. I know those are hints.

Yes, that is the point: not doing that is a mistake. The statement as written does not make any sense: how can you extract 4 elements of a list from “None”? The statement that is throwing the error is this:

(A_prev, W, b, hparameters) = None

That statement makes no sense as written. You need to fix that.

Restarting kernel fixed the traceback error which talked about assigning None. But now it says conv_backward is not defined.

The starting error says syntax error. This is the line that shows error.
A_prev_pad = zero_pad(A_prev, pad)
dA_prev_pad = zero_pad(dA_prev, pad)

  • But now it says conv_backward is not defined.

Restart the kernel
Then “Run All” of the cells in the notebook.

Only then can you trust that the error messages are valid.

Please show us that actual exception trace after doing “Cell → Run All Above”. I already explained why that is necessary to get past the “conv_backward” not defined error.

The other general point to make here is that the python interpreter frequently reports a syntax error on the “next” line if you’ve made an error like omitting a close paren or have left some other form of incomplete syntax on the previous line. So anytime you get a syntax error on a line that looks perfectly fine, please check the previous line or lines for errors.

Thank you…I missed a bracket in the previous line. That’s why there was an error.

Great! It’s a good trick to remember. And it generalizes: it’s always the case that just because the exception gets thrown on a particular line of code does not mean that’s where the actual bug is. :nerd_face:

1 Like

I will remember that. Thank you so much. I was so fixated on the line that I didn’t check anything else.