UnboundLocalError: local variable ‘A’ referenced before assignment
I think “linear_activation_forward” have some error in this assignment.
Could you help me solve this problem?
I tried several things… but I couldn’t solve this error.
This error is very tricky. I followed the error traceback to the definition of linear_activation_forward which is inside dnn_app_utils_v3.py (avaiable to you as well). If we look at its code:
then you can see that the function expected either "sigmoid" or "relu" as the value for activiation. If we have provided anything other than those, then A will never be assigned any value. Consequently, as it ran assert (A.shape == (W.shape[0], A_prev.shape[1])), we would have the local variable ‘A’ referenced before assignment error.
My suggestion is for you to go through the error traceback, check what you had supplied to linear_activation_forward for the activation parameter, and see if you can fix it.
Hi,
I used the below statement while defining the activation function parameter in linear_activation_forward and linear_activation_backward utility funtion. Please use activation = ‘relu’ or ‘sigmoid’ while passing the parameter. it will resolve the issue.
e.g. A1, cache1 = linear_activation_forward(X, W1, b1, activation = “relu”)
or dA1, dW2, db2 = linear_activation_backward(dA2, cache2, activation = ‘sigmoid’)
the function expected either "sigmoid" or "relu" as the value for activiation . If we have provided anything other than those, then A will never be assigned any value. Consequently, as it ran assert (A.shape == (W.shape[0], A_prev.shape[1])) , we would have the local variable ‘A’ referenced before assignment error.
Please look at the activation function carefully, you are providing to the case.