W4_A1_Ex-5_Local variable referenced before Assignment

I got this error and I don’t know were is the problem

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)
28 # caches …
29 # YOUR CODE STARTS HERE
—> 30 A , cache = linear_activation_forward(A_prev, parameters[‘W’ + str(l)], parameters[‘b’ + str(l)], relu)
31 caches.append(cache)
32 # YOUR CODE ENDS HERE

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

UnboundLocalError: local variable ‘activation_cache’ referenced before assignment

Take a look at the code in linear_activation_forward. How could you get to the statement that “throws” without assigning a value to activation_cache? It means you didn’t match either of the “if” conditions, right? That means you passed an incorrect value for the activation parameter. What is it looking for?

Hi @Bilel_Djemel ,

What is happening here is that activation_cache has not been created. It looks like none of the activation calls has been made, possibly because the condition for the ‘if’ statement didn’t match. Please check your code that the input argument activation is checked against a string value, ie. “sigmoid”.

Problem solved!
I just forgot to pass the activation parameter as a string
Thank you!