Course 1 Week 2 programming assignment error

I am working on the cat image recognition assignment. All of the individual functions ran with no errors but when I put them all together in the final model, the following error is occurring:

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

~/work/release/W2A2/ in model_test(target)
123 y_test = np.array([0, 1, 0])
→ 125 d = target(X, Y, x_test, y_test, num_iterations=50, learning_rate=0.01)
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)
41 b = params[“b”]
—> 43 Y_prediction_test = predict(w,b,X_test)
44 Y_prediction_train = predict(w,b,X_train)

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)
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)

Please help me!

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

This means that w does not include enough elements to be reshaped to (4,1). (I think it is (2,1) in this case.) So, please check whether w is calculated correctly or not.

One possibility is,
X is defined as a global variable, and its shape is (2,3). So, if you initialize w (and b) with this, and also used this global variable for optimize(), then the shape of w could be (2,1). So, this error could happen.

So, at first, please double check that any global variables are NOT referred in model(). Then, please keep tracking how w is calculated. Just tracking the shape will give you some hints.