Course 1 week 4 assignment - DNN application

Every time run the DNN implementation, I get this error. I have check the function individually and it works perfectly fine. The error is

Cost after iteration 0: 0.6931477726958
Cost after first iteration: 0.6931477726958
Cost after iteration 1: 0.6930732421651791
Error: Wrong output for variable W1.
Error: Wrong output for variable b1.
Error: Wrong output for variable W2.
Error: Wrong output for variable b2.
Error: Wrong output for variable W3.
Error: Wrong output for variable b3.
Error: Wrong output for variable 0.
Cost after iteration 1: 0.6930732421651791
Cost after iteration 1: 0.6930732421651791
Cost after iteration 2: 0.6927511004095667
Error: Wrong output for variable W1.
Error: Wrong output for variable b1.
Error: Wrong output for variable W2.
Error: Wrong output for variable b2.
Error: Wrong output for variable W3.
Error: Wrong output for variable b3.
Error: Wrong output for variable 0.
2 Tests passed
2 Tests failed

AssertionError Traceback (most recent call last)
in
3 print("Cost after first iteration: " + str(costs[0]))
4
----> 5 L_layer_model_test(L_layer_model)

~/work/release/W4A2/public_tests.py in L_layer_model_test(target)
181 ]
182
→ 183 multiple_test(test_cases, target)

~/work/release/W4A2/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_layer_model. Check your equations and avoid using global variables inside the function.

Are you sure that you did not “copy/paste” over your functions from the Step by Step exercise here? If so, that is a mistake: they provide you with imported versions and the “init” routine works differently.

1 Like

Thank you for the reply. I understood the expectation of the assignment and was able to complete the course. :grinning:

That’s great! Congratulations!

@Ashuthosh I am facing the same error and I too copied the cost function from step_by_step exercise. Could you please describe a little in detail how you arrived at the solution?
I am not able to proceed further.
Thank you!

It is a mistake to copy your functions from the Step by Step exercise: they provide their own imported versions which are a little different in a couple of key places.

Please note: I mentioned this in one of my earlier posts on this thread.

Hi. I tore my hair out for a number of days until I found this post. It isn’t exactly clear that the functions mentioned are imported and that they behave differently than the ones we developed in the step-by-step exercise.

I am a bit surprised that the ones we developed didn’t work for the L-layer model. I’ll not that if I ran the 2-layer model tests using the L-layer model code, it worked. But the assignment exercise with 3 or more layers was definitely wrong.

What surprised me was how small the derivatives were in back-propagation for the first relu layer when using our version of the step-by-step exercise. Can you give a summary/explanation of what was changed between the step-by-step version and the imported version?

Thanks!

You can compare for yourself and see. Click “File → Open” and open the file dnn_app_utils_v3.py. The only difference is in how the initialization function is implemented for the “deep” case (more than two layers). It turns out that the simplistic initialization function that they had us build in the “Step by Step” exercise gives really terrible convergence on the 4 layer model here. Try it for the full training and see how much worse the results are than when you use the imported function. But it works fine for the two layer model, so they left that initialization function the same.

For the deep case, they used a more sophisticated initialization function that we will learn about in DLS C2 W1 called He Initialization. They didn’t explain this and my guess is that there are a couple of potential reasons for not mentioning it:

  1. This is the first course of the series and there is just too much other new material to cover. As you’ll see in C2, it’s not a simple two sentence explanation.
  2. Maybe they didn’t want to call attention to the fact that they have given you the worked solutions to all the functions in the “Step by Step” exercise. Although the “deep init” function would fail the tests in the previous exercise because it’s a different function.