Hello,
I’m currently debugging the code for L-layer model. It’s passing only 1 test. It seems to be pretty simple code but there’s somewhere a bug. I collapsed the code to the bare minimum:
{moderator edit - solution code removed}
I don’t see any global variables here. The initialization looks OK.
I go forward from X to AL then compute cost and backward from Y to AL and at the end I update parameters.
Can you spot what’s wrong here?
The output I get is:
Are you sure that you did not “hand import” your code for the various subroutines from the previous “Step by Step” exercise? If you did that, you will get different results. The reason is that they provided you with those functions and they needed to use a more sophisticated init routine for the “deep” case in order to get decent results.
Actually that’s probably not it: I tried making that mistake and got yet different results. But here’s one other thing: notice that you are appending to the costs array on every single iteration. They already wrote that logic for you and it’s only supposed to happen every 100 iterations, right?
layers_dims = (12288, 7, 1)
Cost after iteration 0: 0.6950464961800915
Cost after first iteration: 0.6950464961800915
layers_dims = (10, 5, 6, 1)
Cost after iteration 1: 0.7070709008912569
layers_dims = (10, 5, 6, 1)
Cost after iteration 1: 0.7070709008912569
layers_dims = (10, 5, 6, 1)
Cost after iteration 1: 0.7070709008912569
layers_dims = (10, 5, 6, 1)
Cost after iteration 2: 0.7063462654190897
All tests passed.
The above are the results I get if I run that test cell with the wrong definition of layers_dims. Note that is set by a separate cell right before the function cell for L_layer_model. If you don’t run that cell, you get the 2 layer version of layers_dims. Interestingly my cost value on the first test case is not the same as you show, but the rest are the same. That is because the other test cases explicitly set layers_dims, as you can see from the print statement I added.
Maybe you used yet a different version of layers_dims of your own creation? Just a theory … Try adding the print and compare your results to mine shown above.
Thanks, I’ve done what you wrote. I restarted a kernel and added a print statement to check the layer_dims
. Everything looked fine.
What actually solved the problem was removing the costs.append(cost)
in a line after calculating the cost.