Error of exercise 5 in Building_your_Deep_Neural_Network_Step_by_Step

Hi There,
I am getting an error in exercise 5. Please kindly help! Thanks very much

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)
23 for l in range(1, L):
24 A_prev = A
—> 25 A, cache = linear_activation_forward(A_prev,parameters[‘W’+str(l)],parameters[‘b’+str(l)], relu)
26
27 caches.append(cache)

in linear_activation_forward(A_prev, W, b, activation)
29
30
—> 31 cache = (linear_cache, activation_cache)
32
33 return A, cache

UnboundLocalError: local variable ‘linear_cache’ referenced before assignment

Take a look at the logic in linear_activation_forward. That error message means you are not taking either of the “if” branches. Why would that happen? Note that the conditions there are using the string name of the activation function. But what you passed is not a string, but actually a reference (pointer) to the function, right?

1 Like

got it, relu and sigmoid should be passed as ‘relu’ and ‘sigmoid’, thanks Paul!

2 Likes