Week 4 assignment 2 problems

I am encountering some problems when I tried to run the code. This is what I got.

Cost after iteration 1: nan
Cost after first iteration: nan
Cost after iteration 1: nan
Cost after iteration 1: nan
Cost after iteration 1: nan
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: nan
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 Traceback (most recent call last)
in
3 print("Cost after first iteration: " + str(costs[0]))
4
----> 5 two_layer_model_test(two_layer_model)

~/work/release/W4A2/public_tests.py in two_layer_model_test(target)
75 ]
76
—> 77 multiple_test(test_cases, target)
78
79

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

For the second exercise, I pretty much encountered the same problem, I checked through my code and I am not really sure what variables I should change so that I can avoid using global ones, I feel like I have already changed all possible ones from using global variables. Can anyone help me?

The lab ID is jeysrhjn

You should not see nan as the cost after any iteration. Since you are using the helper functions like linear_activation_backward for the exercise, please see if you’re passing the right parameters.

If you are certain that there’s nothing wrong with the code, click my name and message your notebook as an attachment.

If you look at the cost in Trackback, even the first cost calculation is not correct. (nan)
In this case, there are really a few chances of errors. The error is most likely a parameter setting for cost calculation, that Balaji pointed out. There may be another bugs in your code, but the first thing that you need to tackle is just a few lines of code, i.e,

A1, cache1 calculation by linear_activation_forward()
A2, cache2 calculation by linear_activation_forward()
cost calculation by compute_cost()

Since those are provided as helper functions, what you need is to check parameters. For example, if you set an activation function “relu” to both, then, “cost” will be “nan”, i.e, “Not a Number”. This is just one example.

Please review carefully for those 3 lines. If you still think you are right, please ask Balaji for a review.

Thanks for the help! The problem has been solved!

That was really helpful, thanks!