Week4 - Assignment2 - Q5 L-layer Neural Network

My two-layer model works fine. But for the L-layer model, I can only pass the 2 tests among 4 of them. I used exactly these functions:


I hope this problem can be fixed. Thank you!

The dimensions of the parameters also seem right in one of the test cases shown here:
W1 shape: (20, 12288)
b1 shape: (20, 1)
W2 shape: (7, 20)
b2 shape: (7, 1)
W3 shape: (5, 7)
b3 shape: (5, 1)
W4 shape: (1, 5)
b4 shape: (1, 1)
A Layer 1 output shape: (20, 209)
A Layer 2 output shape: (7, 209)
A Layer 3 output shape: (5, 209)
A Layer 4 output shape: (1, 209)
dA3 shape: (5, 209)
dW4 shape: (1, 5)
db4 shape: (1, 1)
dA2 shape: (7, 209)
dW3 shape: (5, 7)
db3 shape: (5, 1)
dA1 shape: (20, 209)
dW2 shape: (7, 20)
db2 shape: (7, 1)
dA0 shape: (12288, 209)
dW1 shape: (20, 12288)
db1 shape: (20, 1)
W1 shape after update: (20, 12288)
b1 shape after update: (20, 1)
W2 shape after update: (7, 20)
b2 shape after update: (7, 1)
W3 shape after update: (5, 7)
b3 shape after update: (5, 1)
W4 shape after update: (1, 5)
b4 shape after update: (1, 1)
W1 shape: (20, 12288)
b1 shape: (20, 1)
W2 shape: (7, 20)
b2 shape: (7, 1)
W3 shape: (5, 7)
b3 shape: (5, 1)
W4 shape: (1, 5)
b4 shape: (1, 1)
Cost after iteration 0: 0.6931477726958
Cost after first iteration: 0.6931477726958

But for another test case, it show like this: Error: Wrong output for variable
W1 shape: (5, 10)
b1 shape: (5, 1)
W2 shape: (6, 5)
b2 shape: (6, 1)
W3 shape: (1, 6)
b3 shape: (1, 1)
A Layer 1 output shape: (5, 10)
A Layer 2 output shape: (6, 10)
A Layer 3 output shape: (1, 10)
dA2 shape: (6, 10)
dW3 shape: (1, 6)
db3 shape: (1, 1)
dA1 shape: (5, 10)
dW2 shape: (6, 5)
db2 shape: (6, 1)
dA0 shape: (10, 10)
dW1 shape: (5, 10)
db1 shape: (5, 1)
W1 shape after update: (5, 10)
b1 shape after update: (5, 1)
W2 shape after update: (6, 5)
b2 shape after update: (6, 1)
W3 shape after update: (1, 6)
b3 shape after update: (1, 1)
W1 shape: (5, 10)
b1 shape: (5, 1)
W2 shape: (6, 5)
b2 shape: (6, 1)
W3 shape: (1, 6)
b3 shape: (1, 1)
A Layer 1 output shape: (5, 10)
A Layer 2 output shape: (6, 10)
A Layer 3 output shape: (1, 10)
dA2 shape: (6, 10)
dW3 shape: (1, 6)
db3 shape: (1, 1)
dA1 shape: (5, 10)
dW2 shape: (6, 5)
db2 shape: (6, 1)
dA0 shape: (10, 10)
dW1 shape: (5, 10)
db1 shape: (5, 1)
W1 shape after update: (5, 10)
b1 shape after update: (5, 1)
W2 shape after update: (6, 5)
b2 shape after update: (6, 1)
W3 shape after update: (1, 6)
b3 shape after update: (1, 1)
W1 shape: (5, 10)
b1 shape: (5, 1)
W2 shape: (6, 5)
b2 shape: (6, 1)
W3 shape: (1, 6)
b3 shape: (1, 1)
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.

Are you sure that you did not actually “hand copy” over your functions from the Step by Step assignment? If you do that, then you fail the tests. The reason is that they gave you all the functions here as “imports” and they had to use a more sophisticated “init” function that we will not learn about until Course 2 in order to get decent convergence.

1 Like

Thank you. That is exactly my issue. I don’t know that the init function can help with better convergence. Thanks for letter me know.

1 Like

Yes, it turns out that the initialization function can make a big difference. Please “stay tuned” and that will be one of the many interesting topics covered in DLS Course 2. Hope to see you there now that you’re done with Course 1. Congrats!

1 Like