Course1: Week 4 - assignment 2

I have a problem with the two_layer_model and get the following error and would appreciate, if anyone could provide me with a hint, what could be wrong.

UnboundLocalError Traceback (most recent call last)
in
----> 1 parameters, costs = two_layer_model(train_x, train_y, layers_dims = (n_x, n_h, n_y), num_iterations = 2, print_cost=False)
2
3 print("Cost after first iteration: " + str(costs[0]))
4
5 two_layer_model_test(two_layer_model)

in two_layer_model(X, Y, layers_dims, learning_rate, num_iterations, print_cost)
49 # YOUR CODE STARTS HERE
50
—> 51 A1, cache1 = linear_activation_forward(X, W1, b1, relu)
52 A2, cache2 = linear_activation_forward(A1, W2, b2, sigmoid)
53

~/work/release/W4A2/dnn_app_utils_v3.py in linear_activation_forward(A_prev, W, b, activation)
209 A, activation_cache = relu(Z)
210
→ 211 assert (A.shape == (W.shape[0], A_prev.shape[1]))
212 cache = (linear_cache, activation_cache)
213

UnboundLocalError: local variable ‘A’ referenced before assignment

It is a general principle of debugging that an error may be thrown in a function that is perfectly correct, if you pass it incorrect arguments. Take a look at the logic in linear_activation_forward to see why you are not taking either of the branches based on the activation argument that you passed. That logic expects the string name of the function, right? What you are passing is a python object reference to the function. That is not the same thing, which is why neither of the paths are taken and A is never assigned a value.

Thanks a lot for the help, the code is working now!