Getting Test Case Failures in L_layer_model (Week 4 – Deep Neural Network Application)

I am encountering an issue in the Week 4 assignment: “Deep Neural Network – Application.”
In the function L_layer_model, 2 test cases are passing and 2 are failing.
Please help me identify and resolve the problem.

This could be caused by the same thing that caused your previous error: using your own functions from the Step by Step exercise. Are you sure you removed all those and are using the ones they gave you?

If that’s not the problem, then here are a few more things to check:

  1. Make sure you actually ran the cell that defines layers_dims for the L layer network.
  2. Make sure you did not hard-code the learning rate when you call update_parameters from L_layer_model.

The cost value you are getting also differs from what I see. Also note that I added a print statement to show the current layers_dims value in the L_layer_model function:

layers_dims = [12288, 20, 7, 5, 1]
Cost after first iteration: 0.7717493284237686
layers_dims = (10, 5, 6, 1)
layers_dims = (10, 5, 6, 1)
layers_dims = (10, 5, 6, 1)
layers_dims = (10, 5, 6, 1)
 All tests passed.

I tried the experiment of using the initialize_parameters_deep function from the Step by Step exercise and I get exactly the same wrong cost value you show:

layers_dims = [12288, 20, 7, 5, 1]
Cost after first iteration: 0.6931477726958
layers_dims = (10, 5, 6, 1)
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.

If you didn’t remove your hand copied functions, then how did you pass the two_layer_model problem from the previous question you asked?

It turns out that in order to get good convergence in the L layer case, they had to use a more sophisticated initialization algorithm that we will learn about in DLS Course 2. They didn’t talk about this, but provided the new function in the import file. This is the first course of the series and there is just too much to cover. Please stay tuned to learn much more in Course 2 and the other courses in this series.

1 Like

I just changed costs.append(cost) to costs.append(np.array(cost)).

So if I remove the initialize_parameters_deep function, will the test cases pass?

Yes, you can remove all the extra functions you added, including compute_cost. Check the “import” cell at the beginning of the notebook. All the “Step by Step” functions are provided by the file dnn_app_utils_v3.py, which is imported there.

I’ll check it, sir. Thank you. I’ll message you after testing.