Programming Assignment: Building your Deep Neural Network: Step by Step

I’m having trouble interpreting the following error message for the L_model_forward function.

One thing I don’t understand in the function is this line
L = len(parameters) // 2 # number of layers in the neural network
I don’t understand the // 2 and why this is necessary

Also, when accessing the parameters for a specific layer, is the following, correct?
parameters[‘W’ + str(l)], parameters[‘b’ + str(l)]

AL = [[0.90589057 0.75020632 0.05200643 0.82351754]
[0.99823392 0.08462048 0.01610661 0.98885794]
[0.9999688 0.33941221 0.83703792 0.99971951]]
Error: Wrong shape for variable 0.
Error: Wrong shape for variable 0.
Error: Wrong shape for variable 1.
Error: Wrong shape for variable 2.
Error: Wrong shape for variable 1.
Error: Wrong output for variable 0.
Error: Wrong output for variable 0.
Error: Wrong output for variable 1.
Error: Wrong output for variable 2.
Error: Wrong output for variable 1.
1 Tests passed
2 Tests failed


AssertionError Traceback (most recent call last)
in
4 print("AL = " + str(t_AL))
5
----> 6 L_model_forward_test(L_model_forward)

~/work/release/W4A1/public_tests.py in L_model_forward_test(target)
321 ]
322
→ 323 multiple_test(test_cases, target)
324 ‘’’ {
325 “name”:“datatype_check”,

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

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

Thanks in advance,
Albert

You can actually look at the contents of the parameters dictionary. One way is:

print(parameters.keys())

Or you can examine the test code by clicking “File → Open” and opening the appropriate python file. Find the source code that creates the test inputs to see how the parameters dictionary is constructed.

But the point is that there are two parameters for each layer: W^{[l]} and b^{[l]}, which is why we need to divide by 2 there.

The error messages from the test mean your code is generating incorrect values. It could be that either the A^{[L]} value is wrong or that the caches are not correct. Notice that the error messages say that even the shapes of your values are incorrect.

One good way to start debugging in a case like this is to do the “dimensional analysis”, so that you know what you should be expecting at each layer. Here’s a thread which walks you through that for the test case here.

Thanks, Paul. Hopefully, I’ll be able to fix my code with these debugging tips and the thread you linked to.

Albert

1 Like

@siral important to note that // is ‘integer division’ (as opposed to just /), so we toss away the remainder here. Basically, we try to divide len(parameters) by 2 as equally as we can.

1 Like

Thanks, I’ll keep that in mind as I debug my code.