W4_A1_Ex-8_Unbound local error

Hi

Would you please let me know how to fix the following error message or I can ignore the following error message?

I just want to make sure what I did in the lab is correct.

Thanks
Ming

[ValidateApp | INFO] Validating ‘/home/jovyan/work/submitted/courseraLearner/W4A1/Building_your_Deep_Neural_Network_Step_by_Step.ipynb’
[ValidateApp | INFO] Executing notebook with kernel: python3
Tests failed on 2 cell(s)! These tests could be hidden. Please check your submission.

The following cell failed:

t_dAL, t_linear_activation_cache = linear_activation_backward_test_case()

t_dA_prev, t_dW, t_db = linear_activation_backward(t_dAL, t_linear_activation_cache...
print("With sigmoid: dA_prev = " + str(t_dA_prev))
print("With sigmoid: dW = " + str(t_dW))
print("With sigmoid: db = " + str(t_db))

t_dA_prev, t_dW, t_db = linear_activation_backward(t_dAL, t_linear_activation_cache...
print("With relu: dA_prev = " + str(t_dA_prev))
print("With relu: dW = " + str(t_dW))
print("With relu: db = " + str(t_db))

linear_activation_backward_test(linear_activation_backward)

The error was:

---------------------------------------------------------------------------
UnboundLocalError                         Traceback (most recent call last)
<ipython-input-18-1dd7958789b5> in <module>
      1 t_dAL, t_linear_activation_cache = linear_activation_backward_test_case()
      2 
----> 3 t_dA_prev, t_dW, t_db = linear_activation_backward(t_dAL, t_linear_activati...
      4 print("With sigmoid: dA_prev = " + str(t_dA_prev))
      5 print("With sigmoid: dW = " + str(t_dW))

<ipython-input-17-d9319b669d2e> in linear_activation_backward(dA, cache, activation...
     37         # YOUR CODE ENDS HERE
     38 
---> 39     return dA_prev, dW, db

UnboundLocalError: local variable 'dA_prev' referenced before assignment

==========================================================================================
The following cell failed:

t_AL, t_Y_assess, t_caches = L_model_backward_test_case()
grads = L_model_backward(t_AL, t_Y_assess, t_caches)

print("dA0 = " + str(grads['dA0']))
print("dA1 = " + str(grads['dA1']))
print("dW1 = " + str(grads['dW1']))
print("dW2 = " + str(grads['dW2']))
print("db1 = " + str(grads['db1']))
print("db2 = " + str(grads['db2']))

L_model_backward_test(L_model_backward)

The error was:

---------------------------------------------------------------------------
UnboundLocalError                         Traceback (most recent call last)
<ipython-input-20-3ace16762626> in <module>
      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']))

<ipython-input-19-8f59288cd76d> in L_model_backward(AL, Y, caches)
     40     # YOUR CODE STARTS HERE
     41     current_cache = caches[L-1]
---> 42     dA_prev_temp, dW_temp, db_temp = linear_activation_backward(dAL, curren...
     43     grads["dA" + str(L-1)] = dA_prev_temp
     44     grads["dW" + str(L)] = dW_temp

<ipython-input-17-d9319b669d2e> in linear_activation_backward(dA, cache, activation...
     37         # YOUR CODE ENDS HERE
     38 
---> 39     return dA_prev, dW, db

UnboundLocalError: local variable 'dA_prev' referenced before assignment

Hello, Ming Han.

Welcome to the community.

This means that you have hard-coded any value while calling the function.

ValidateApp error is thrown when your copy needs to be cleaned and bug free. Please use this link to get a clean copy.

There appears to be an error in your linear_activation_backward(…) function with regard to the variable dA_prev.

Yes, that’s an error that you need to resolve. Please have a more careful look at the template code logic that they gave you. Where does it set dA_prev in that logic? It’s in two places and which place gets executed depends on the value of the activation parameter that is passed, right? But if the value you passed does not match either choice, then the variable ends up not getting set. So please look again at your code and ask yourself how that could happen … Note that just because the error is thrown in linear_activation_backward, that doesn’t prove that’s where the error is. A perfectly correct function can still throw errors if you pass it bad or mismatching parameters.

When the code you wrote doesn’t work, then you need to apply the kind of thought process that I just described there. First look at the error message. What does it mean? Then you have to work backwards to figure out how it happened. If you’re new to programming, it’s a mistake to think of debugging as a “side issue” or some annoying thing that you can just try to ignore. It is a key part of the job of being a programmer. What’s the point if you can’t get your code to work?

Thank you all. The problem was solved.