Hello,
I am getting following error in the Exercise 2: dW3 = (lambd/m)*W3
AssertionError: Not all tests were passed for backward_propagation_with_regularization. Check your equations and avoid using global variables inside the function.
Please let me know. Thank you
1 Like
Hi @Paresh1,
Look at the example just right before your code:
#(â 1 lines of code)
# dW3 = 1./m * np.dot(dZ3, A2.T) + None
# YOUR CODE STARTS HERE
The example is giving you the computation of dW3 without regularization.
To include regularization you need to add the regularization term to the original computation.
In order to do that, you just need to replace None with the regularization term.
3 Likes
I couldnât understand why there was a None is there, thank you very much.
That is one of the ways they indicate the places where you need to add code: by using None as a placeholder. Anyplace you see None, you need to examine carefully. There are a (very) few instances (mostly in later courses) where there are None values that are real code, but mostly it indicates something you need to change.
1 Like
where there are None values that are real code, but mostly it indicates something you need to change.
Thank you. I was genuinely stumped by what the âNoneâ term was supposed to represent
Hello, I still face the same error above after adding this part dW3 = 1./m * np.dot(dZ3, A2.T) with regularization term (lambd/m)*W3. Couldnât understand why, please help!!!
That is not the only line of code you need to modify in that routine, right? Note that you canât really tell which value it is upset about from just that error message. Maybe your dW3 is correct, but dW2 is wrong âŚ
Also note that just typing new code and then calling the function again does not do anything: it just runs the old code again. You need to click âShift-Enterâ on the changed function cell first to get the new code compiled. Then call the function again. Or try âKernel â Restart and Clear Outputâ followed by âCell â Run Allâ and see what happens. Thatâs a âsledgehammerâ way to make sure everything is in a consistent state.
Please correct me if Iâm wrong, I modify all there lines of code in this excercise the same way, which is adding regularization term (lambd/m) * W[layer] to the code given in #, i.e for second layer I have dW2 = 1./m * np.dot(dZ2, A1.T) + (lambd/m)* W2.
I also rerun the chunk many times and still face the same error
You can examine the test code to see what it is looking for and then instrument your code to explore what is wrong. The tests are in the file public_tests.py. Just click âFile â Openâ and then find that file.
Can you show us the printed out output values that you get when you run that test cell? Not just the assertion failure, but the dW values that get printed before that. For example, here is what I get when I run that cell:
dW1 =
[[-0.25604646 0.12298827 -0.28297129]
[-0.17706303 0.34536094 -0.4410571 ]]
dW2 =
[[ 0.79276486 0.85133918]
[-0.0957219 -0.01720463]
[-0.13100772 -0.03750433]]
dW3 =
[[-1.77691347 -0.11832879 -0.09397446]]
All tests passed.
What do you see? Are your values the same as mine? Note that the test case comes after that and it may well use different inputs.
Update: I looked at the test and it uses the same input values, so the results should be the same. A couple of points, though:
- The first test that passes is just checking the shapes of the outputs, not the actual values. So your shapes are correct.
- Note that the test case in public_tests.py checks all the outputs, not just dW1, dW2 and dW3. So if you modified any of the given template code that computes, say, the dZ, dA and db values, that will cause problems.
Here are my dW values, as you can see dW1 and dW2 are similar but dW3 are different. I donât know how it can happen as I compute them the same way? Here is my dW3
dW3 = 1./m + np.dot(dZ3, A2.T) + (lambd/m)* W3
If that is literally a âcopy/pasteâ of that line, then that is the problem. What is the operation between that first 1./m and the np.dot? You have written addition, but itâs supposed to be multiplication, right? Note that code was given to you in the comment, so it must have just been some kind of typing accident that caused it to get rewritten in that way.
1 Like
Thatâs actually the error, I canât believe I made that careless mistake. Thanks a lot for your time