Course 1, Week 2, Training

Hello, All tests passed for model but while training model I get an error:

ValueError                                Traceback (most recent call last)
<ipython-input-72-b8051f6b0651> in <module>
----> 1 logistic_regression_model = model(train_set_x, train_set_y, test_set_x, test_set_y, num_iterations=2000, learning_rate=0.005, print_cost=True)

<ipython-input-70-cb4dfefaeb99> in model(X_train, Y_train, X_test, Y_test, num_iterations, learning_rate, print_cost)
     39     w,b =initialize_with_zeros(dim)
     40 
---> 41     params,grads,costs = optimize(w, b, X_train, Y_train, num_iterations, learning_rate, print_cost)
     42 
     43     w = params["w"]

<ipython-input-66-21f24d444247> in optimize(w, b, X, Y, num_iterations, learning_rate, print_cost)
     36         # YOUR CODE STARTS HERE
     37 
---> 38         grads, cost = propagate(w, b, X, Y)
     39 
     40         # YOUR CODE ENDS HERE

<ipython-input-64-bb610b980e64> in propagate(w, b, X, Y)
     33     y_reshaped = Y.reshape(Y.shape[0] * Y.shape[1], 1)
     34 
---> 35     A = sigmoid(sum((np.dot(np.transpose(w), X)) , b))
     36     #A = sigmoid (np.dot(w.T,X) +b)
     37 

<__array_function__ internals> in dot(*args, **kwargs)

ValueError: shapes (1,4) and (12288,209) not aligned: 4 (dim 1) != 12288 (dim 0)

Can anyone help me figure the problem out?

I bet I “hardcoded” something somewhere although I have checked for that too.

It’s not quite “hard-coding”, but it is a similar type of error. You have referenced a global variable when you call the initialize routine, rather than referencing the parameters to model. The value of that variable turns out to have nothing to do with the test case at hand.

In order to debug this on your own, the point is that your w is the wrong shape by the time you get down into propagate. But the bug is not in propagate, even though that is where the error is “thrown”. propagate does not modify the value of w, right? So where is the shape of w determined? You have to trace back up the call stack to figure out where the error actually is.