W3_A1_Ex-8_nn_model_parameters referenced before assignment

This is my code, and I get parameters in line parameters = initialize_parameters(n_x, n_h, n_y) before it’s referenced as you see below,
but I keep encountering an error such UnboundLocalError: local variable ‘parameters’ referenced before assignment

Can you please take a look?

====================. MY CODE ==========================
{moderator edit - solution code removed}

============== Error mesage ====================


UnboundLocalError Traceback (most recent call last)
in
----> 1 nn_model_test(nn_model)

~/work/release/W3A1/public_tests.py in nn_model_test(target)
261
262 t_X, t_Y = nn_model_test_case()
→ 263 parameters = target(t_X, t_Y, n_h, num_iterations=10000, print_cost=True)
264
265 print("W1 = " + str(parameters[“W1”]))

in nn_model(X, Y, n_h, num_iterations, print_cost)
34 # Forward propagation. Inputs: “X, parameters”. Outputs: “A2, cache”.
35 # A2, cache = …
—> 36 A2, cache = forward_propagation(X, parameters)
37
38

UnboundLocalError: local variable ‘parameters’ referenced before assignment

Hi @satang500 ,

It looks like the initialize_parameters() function failed to return any value, hence the error message. Check the code for initialize_parameters()

Yes, something must be wrong with that call to initialize_parameters. The code looks correct that we can see, although I’m a bit worried about the indentation. I hope this is just a “copy/paste” artifact, but it looks like the body of the nn_model function is not indented. I hope in your notebook it doesn’t look the way it looks in your post.

I guess the other possibility is that maybe you are using different language settings in your browser and some strange or invisible characters got inserted in the code somehow that we can’t see. I would start by using the browser search (command-F on Mac) to search for the string “parameters” in that function and make sure it matches where you expect it to.

BTW in general it’s against the rules to post your code in a public way.