(Week 2 assignment) Merge all functions into a model

I can pass all the tests separately. However, while merging I am getting the error as given below and I am not able to figure out the problem.
Please help me out!! Thank you.

the error is:
ValueError Traceback (most recent call last)
in
----> 1 model_test(model)

~/work/release/W2A2/public_tests.py in model_test(target)
109 y_test = np.array([1, 0, 1])
110
→ 111 d = target(X, Y, x_test, y_test, num_iterations=50, learning_rate=1e-4)
112
113 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 = param[“b”]
42
—> 43 Y_prediction_train = predict(w, b, X_train)
44 Y_prediction_test = predict(w, b, X_test)
45

in predict(w, b, X)
18 print(X.shape[0])
19 Y_prediction = np.zeros((1, m))
—> 20 w = w.reshape(X.shape[0], 1)
21
22 # 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)

@jaydippokiya the parameter dim is not part of the model function definition therefore unless you have properly calculated it before you may be referencing dim as a global variable and as a consequence that is causing the shape error.

def model(X_train, Y_train, X_test, Y_test, num_iterations=2000, learning_rate=0.5, print_cost=False):

@albertovilla

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-26-9408a3dffbf6> in <module>
      1 from public_tests import *
      2 
----> 3 model_test(model)

~/work/release/W2A2/public_tests.py in model_test(target)
    113     y_test = np.array([0, 1, 0])
    114 
--> 115     d = target(X, Y, x_test, y_test, num_iterations=50, learning_rate=0.01)
    116 
    117     assert type(d['costs']) == list, f"Wrong type for d['costs']. {type(d['costs'])} != list"

<ipython-input-25-6c7f62fde327> in model(X_train, Y_train, X_test, Y_test, num_iterations, learning_rate, print_cost)
     34 
     35     # Predict test/train set examples (≈ 2 lines of code)
---> 36     Y_prediction_test = predict(w, b, X_test)
     37     Y_prediction_train = predict(w, b, X_train)
     38 

<ipython-input-17-6a133a26bbf0> 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 16 into shape (4,1)

I traced the issue back to computation of dw .

the dw array is coming out of the size (4,4),
on closer observation its turn out that during optimization the w - alpha * dw operation does a broadcast operation and changes size of w from (4,1) to (4,4).

Please help me out .

Please find the function call below .

 # (≈ 1 line of code)   
    # initialize parameters with zeros 
    w, b = np.zeros((X_train.shape[0],1)) , np.zeros((X_train.shape[0],1))

    
    
    #(≈ 1 line of code)
    # Gradient descent 
    params, grads, costs = optimize(w, b, X_train, Y_train, num_iterations, learning_rate, print_cost=False)
    
    # Retrieve parameters w and b from dictionary "params"
    w = params["w"]
    b = params["b"]
    
    
    # Predict test/train set examples (≈ 2 lines of code)
    Y_prediction_test = predict(w, b, X_test)
    Y_prediction_train = predict(w, b, X_train)