W4_A1_Ex-5_Local variable_linear_cache referenced before assignment

{moderator edit - solution code removed}

UnboundLocalError Traceback (most recent call last)
in
1 t_X, t_parameters = L_model_forward_test_case_2hidden()
----> 2 t_AL, t_caches = L_model_forward(t_X, t_parameters)
3
4 print("AL = " + str(t_AL))
5

in L_model_forward(X, parameters)
27 # caches …
28 # YOUR CODE STARTS HERE
—> 29 A, cache = linear_activation_forward(A, parameters[“W” + str(l)], parameters[“b” + str(l)], relu)
30 caches.append(cache)
31 # YOUR CODE ENDS HERE

in linear_activation_forward(A_prev, W, b, activation)
37
38 # YOUR CODE ENDS HERE
—> 39 cache = (linear_cache, activation_cache)
40
41 return A, cache

UnboundLocalError: local variable ‘linear_cache’ referenced before assignment

Hey there, Can anyone help me with this error??

Please note that the rules are that we’re not supposed to publicly post solution code here or in any other public place (e.g. github). We could have answered this question just by seeing the exception trace that you showed. But no harm is done: I edited your post to remove the code.

Well, look at the code in linear_activation_forward and ask how you could fall through to the line that “throws” without setting the cache value? It means you didn’t match either of the “if” conditions, right? So how could that happen? Look at the values you passed for the activation argument when you called that function from L_model_forward: those values don’t match either of the conditions. Can you see why?

1 Like

Yes I certainly can, Thank You very much for helping me out.