Week 4 programming assignment: Deep Neural Network - Application

Hi there,

For the two_layer_model, I kept getting this following error:

Cost after iteration 1: 0.6564026188409187
Cost after first iteration: 0.6950464961800915
Cost after iteration 1: 0.7239781229671559
Cost after iteration 1: 0.7239781229671559
Cost after iteration 1: 0.7239781229671559
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 0.
Cost after iteration 2: 0.6372332154479152
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 0.
2 Tests passed
2 Tests failed
“AssertionError: Not all tests were passed for two_layer_model. Check your equations and avoid using global variables inside the function.”

I examined my whole code and don’t think I used only the input variables, specifically, I used learning_rate as update_parameters(parameters, grads, learning_rate). On the other hand, for the L_layer_model, the same code pass test without error.

Can somehow help find out what’s wrong? Thanks!

Lu

Hey @Lu_Huang,
Welcome to the community. Can you please DM your code for the two_layer_model function to me, so that I can help you figure out the issue.

Cheers,
Elemento

Just did, thanks a lot for the quick reply!

Hey @Lu_Huang,
You have used the initialize_parameters_deep function instead of the initialize_parameters function in your two_layer_model function. The former function is for the L-layered model, while the later is for the 2-layered model. Also, when you are passing arguments to the initialize_parameters function, you are supposed to pass them individually, whereas you have passed them as a tuple. I hope this helps.

Cheers,
Elemento

Oh, got it, thanks a lot for the help!

Wait, for the assignment we are dealing with here, initialize_parameters and initialize_parameters_deep have exactly same logic, is the difference because of random seed?

Hey @Lu_Huang,
If you check out the implementations of initialize_parameters and initialize_parameters_deep that have been imported and used in this assignment (which you can view in the dnn_app_utils_v3.py file), you will find that in both the cases, the random seed is the same, and in fact, the implementations slightly differ which gives rise to this error.

Had you been using the functions that you implemented yourself in the previous assignment, the difference would indeed be of random seed, but in this case, it is not as I just mentioned before.

Feel free to check out the imported implementations and see the difference. Now, as to why this difference is done, perhaps the developers might have received better performance by the L-layered model by incorporating this difference. Once again, feel free to use your implemented functions, and see if this difference gives any advantage or not. Do share your results with the community.

Cheers,
Elemento

Exactly. It turns out that if you use the “plain vanilla” version of initialize_parameters_deep that they had us build in the “Step by Step” exercise, you get really terrible convergence for the 4 layer model here. So they used a more sophisticated algorithm called Xavier Initialization that we will learn about in Course 2 of this series, so stay tuned for that. I think they didn’t mention this just because there is already enough new material to be learned in Course 1 and they didn’t want to further muddy the waters. Well that and I’m guessing they didn’t want to reveal that they’d given you the worked answers for the “Step by Step” exercise as an “import” file in the W4 A2 assignment. Of course if you’d copied the “deep init” code, it would have failed the tests in “Step by Step” because the algorithm is different. :nerd_face:

2 Likes