Course1:Week4:Exercise9:L_model_backward

UnboundLocalError Traceback (most recent call last)
in
1 t_AL, t_Y_assess, t_caches = L_model_backward_test_case()
----> 2 grads = L_model_backward(t_AL, t_Y_assess, t_caches)
3
4 print("dA0 = " + str(grads[‘dA0’]))
5 print("dA1 = " + str(grads[‘dA1’]))

in L_model_backward(AL, Y, caches)
40 # YOUR CODE STARTS HERE
41 current_cache = caches
—> 42 dA_prev_temp, dW_temp, db_temp = linear_activation_backward(dAL, current_cache, activation=sigmoid)
43 grads[“dA” + str(L-1)] = dAL-1
44 grads[“dW” + str(L)] = dWL

in linear_activation_backward(dA, cache, activation)
36 # YOUR CODE ENDS HERE
37
—> 38 return dA_prev, dW, db

UnboundLocalError: local variable ‘dA_prev’ referenced before assignment

linear_activation_backward returns the dA_prev that is stored in dA_prev_temp. then how it’s referenced before assignment?

It is because you have passed an incorrect value for the activation parameter. That causes neither of the branches which would set dA_prev to be taken. Take a look at the logic in the called routine and compare what you passed to the boolean selection conditions there and it should become clear what happened. The point is that the error is being thrown within the scope of linear_activation_backward.

1 Like