W4_A2_E1 i have implemented the code correctly for two layer model but its showing me the following error: UnboundLocalError

Error! Please make sure you have passed the value correctly in the “activation” parameter

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)
47 # YOUR CODE STARTS HERE
48 A1, cache1 = linear_activation_forward(X, W1, b1, ‘relu’)
—> 49 A2, cache2 = linear_activation_forward(A1, W2, b2, ‘softmax’)
50
51 # YOUR CODE ENDS HERE

~/work/release/W4A2/dnn_app_utils_v3.py in linear_activation_forward(A_prev, W, b, activation)
212 print(“\033[91mError! Please make sure you have passed the value correctly in the "activation" parameter”)
213
→ 214 assert (A.shape == (W.shape[0], A_prev.shape[1]))
215 cache = (linear_cache, activation_cache)
216

UnboundLocalError: local variable ‘A’ referenced before assignment

@Shabaz at first glance at least one of your activations is wrong. Reread the assignment carefully. Think, how many values do we expect for Y-hat ?

2 Likes

Hi @Shabaz ,

For activation function for the output layer is ‘sigmoid’, not ‘softmax’, because the model is to classify if the image is cat or not cat, a binary classifier, not a multiclass one. The utility function linear_activation_forward() has no activation function for ‘softmax’ , and ‘A’ therefore is not defined within that function, resulting the errors as reported.

3 Likes