Week 4 NN Application initatize parameters

I pass layers_dims to set the parameters, but the function does not seem to see all the members of the tuple. As far as I can find out the tuple is not passed with the brackets that appear from print()??

parameters, costs = two_layer_model(train_x, train_y, layers_dims = (n_x, n_h, n_y), num_iterations = 2, print_cost=False)

print("Cost after first iteration: " + str(costs[0]))

two_layer_model_test(two_layer_model)

layers_dims (12288, 7, 1)


TypeError 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)
29
30 print(‘layers_dims’, layers_dims)
—> 31 parameters = initialize_parameters(layers_dims)
32
33 # YOUR CODE ENDS HERE

TypeError: initialize_parameters() missing 2 required positional arguments: ‘n_h’ and ‘n_y’

Hey @Brendon_Wolff-Piggot,
Please check out the implementation of initialize_parameters in Week 4 Assignment 1. You will find that the function takes the size of the input, hidden and output layers as separate arguments and not as a tuple. Also, in your code, you are using layers_dims which is a tuple, and hence the issue. Let me know if this helps.

Cheers,
Elemento

1 Like