Exercise 8 Model: Issue with shape of X_Train

In multiline comments of model function it states:

X_train – training set represented by a numpy array of shape (num_px * num_px * 3, m_train)

However, when I print the shape of X_train I get (4, 7)

here is the traceback after running the code:

(4, 7)

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)
39 w, b = initialize_with_zeros(num_px * num_px * 3)
40
—> 41 params, grads, costs = optimize(w, b, X_train, Y_train, num_iterations, learning_rate, print_cost)
42
43 w = params[‘w’]

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

in propagate(w, b, X, Y)
31 # YOUR CODE STARTS HERE
32
—> 33 A = sigmoid(np.dot(w.T, X) + b)
34 cost = (-1/m) * (np.sum(np.dot(Y, np.log(A).T) + np.dot((1 - Y), np.log(1 - A).T)))
35

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

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

Please advise. I am unsure if I made a mistake somewhere (entirely possible), but after spending quite some time debugging, I think the error is with X_train because the shape is wrong…

Any help would be greatly appreciated!

Hi @Joseph_Caldwell ,

Actually, when you test the model function, the shape of the 2 tests are (4, 7) and (4, 3), so that looks fine.

It seems your error is happening when you start training your model, and at that point your X_train is the train_set_x which is created above in Exercise 2. You may want to start by checking your earlier exercises.

That type of error usually means you are referencing global variables from the local scope of the model function. E.g. it is a mistake to reference train_set_x directly there, since that may not be what is actually passed to the function, as we see in this case.

Had the same issue. It works for me:

under def model(), change the initialization code to

{moderator edit - solution code removed}

I previous wrote w, b = initialize_with_zeros(num_px*num_px*3)