W2_A2_Ex-8_Error in function that passed tests

Hey guys, I am getting an error that I cannot solve in Ex8.
All functions have passed all tests previously, but when I try to use them in the def(model) function, I get the following error:


ValueError Traceback (most recent call last)
in
1 from public_tests import *
2
----> 3 model_test(model)

~/work/release/W2A2/public_tests.py in model_test(target)
123 y_test = np.array([[0, 1, 0]])
124
→ 125 d = target(X, Y, x_test, y_test, num_iterations=50, learning_rate=0.01)
126
127 assert type(d[‘costs’]) == list, f"Wrong type for d[‘costs’]. {type(d[‘costs’])} != list"

in model(X_train, Y_train, X_test, Y_test, num_iterations, learning_rate, print_cost)
43 b = params[‘b’]
44
—> 45 Y_prediction_test = predict(w,b,X_test)
46 Y_prediction_train = predict(w,b,X_train)
47

in predict(w, b, X)
16 m = X.shape[1]
17 Y_prediction = np.zeros((1, m))
—> 18 w = w.reshape(X.shape[0], 1)
19
20 # Compute vector “A” predicting the probabilities of a cat being present in the picture

ValueError: cannot reshape array of size 2 into shape (4,1)

Anyone know how to solve this?

1 Like

If your previous functions passed the tests, then the bug is in model. But if you got through the optimize call without any errors being thrown and fail on the predict, then my guess is you did not correctly handle retrieving the w value as a return value from optimize. How does that work? Take another look at the logic. The w value you are passing to that predict call is wrong, so how could that happen?

oh my, I called parms, grads, costs = Optimize(…) instead of params, grads costs= Optimize(…). I’ve been debugging for 2 hours straight :sweat_smile: thank you!

Glad to hear that you found the issue!