Expected result:
AL = [[0.03921668 0.70498921 0.19734387 0.04728177]]
What I’m getting:
AL = [[0.03921668 0.70498921 0.19734387 0.04728177]]
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 1.
Error: Wrong output for variable 2.
Error: Wrong output for variable 1.
0 Tests passed
3 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)
238 ]
239
→ 240 multiple_test(test_cases, target)
241 ‘’’ {
242 “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.
Please help!!
Here’s the full test cell:
t_X, t_parameters = L_model_forward_test_case_2hidden()
t_AL, t_caches = L_model_forward(t_X, t_parameters)
print("AL = " + str(t_AL))
L_model_forward_test(L_model_forward)
So what your output shows is that you got the correct AL value on the first test case (the “2hidden” test from the file testCases.py), which is actually pretty complicated, so your code must be pretty close. But then you fail completely on the other test case which is in the file public_tests.py. You can look at that test case and see the shapes of the inputs for that test case and find out that it is exactly the same as the “2hidden” test case, but what it checks as the results in addition to AL is the “caches” value that is the second return value. So that is where you need to look: the evidence suggests that the handling of your cache values is not correct.
1 Like
It’s actually amazing how fast you give feedback! Thank you very much
I passed every test before this one. Everything green.
The only new thing related to cache is the following instruction
caches.append(cache)
Which I guess it’s just fine… I can’t find what’s wrong.
That looks fine, but the question is what is the value of the cache variable in that statement. It should be a 2-tuple that looks like this:
((A,W,b), Z)
Where the first element of the 2-tuple is itself a 3-tuple and the second element is a single value.
The cache variable is defined as cache = (linear_cache, activation_cache)
Where linear_cache is returned by linear_forward(A_prev, W, b)
and
activation_cache is returned by sigmoid(Z) or relu(Z)
I’m unable to find my mistake.
EDIT::
In L_model_forward
Am I calling the function alright?
{moderator edit - solution code removed}
1 Like
Yes, that looks correct. Are you sure you checked that the contents of cache returned by linear_activation_forward is correct?
I solved the problem simply by redoing the whole assignment…
Something must have been bugged on my way to exercise 5…
It’s really strange because I wrote exactly the same code I had, on every exercise, yet now it worked.
Thank you very much for your assistance!!!
Glad to hear you found a solution. It must have been something pretty subtle. You can actually download the before and after notebooks as “ipynb” files and run the “diff” command on them. They are JSON text files. Of course you’ll want to be careful to do “Kernel → Restart and Clear Output” before you do the downloads to remove all the voluminous generated output (print statements from running the various cells), so that you can clearly see just the source code.
But maybe it doesn’t matter if you have it correct now. Just if you are bugged by the idea of a mysterious unexplained mistake!
I have the same error! I spend lots of time to understand what’s wrong but I could not understand!
Please show us the actual error output that you are getting.
Your code works perfectly fine, your question actually solved one of my problems of computing AL. You must check your previous functions are generating the right dimensions in output.