Question on Exercise 8 Lab 1 Week 2

When creating a post, pleaseHello,

I am having trouble implementing the method “model” with Excersize 8 on Lab1 week 2.

I initialized w and b using the initialize_with_zeros method w of shape (4 ,1).

I called optimize passing in the other variables that were passed into model().

I passed X_train and Y_train into optimize() but I dont know if that is correct.

X is data of shape (num_px * num_px * 3, number of examples) and Y is a true “label” vector (containing 0 if non-cat, 1 if cat), of shape (1, number of examples).

Also I have a question with calling ther predict method with X_Test for Y_prediction_ test and X_train for Y_prediction_test

Here is my output:

#X_train
[[ 1.76405235 0.40015721 0.97873798 2.2408932 1.86755799 -0.97727788
0.95008842]
[-0.15135721 -0.10321885 0.4105985 0.14404357 1.45427351 0.76103773
0.12167502]
[ 0.44386323 0.33367433 1.49407907 -0.20515826 0.3130677 -0.85409574
-2.55298982]
[ 0.6536186 0.8644362 -0.74216502 2.26975462 -1.45436567 0.04575852
-0.18718385]]
[[0.]
[0.]
[0.]
[0.]]
({‘w’: array([[ 0.08639757],
[-0.08231268],
[-0.11798927],
[ 0.12866053]]), ‘b’: -0.039832360948163205}, {‘dw’: array([[-0.15608203],
[ 0.15736202],
[ 0.21618227],
[-0.22969068]]), ‘db’: 0.08648594658415165}, [array(0.69314718)])
[array(0.69314718)]

AssertionError 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)
127 assert type(d[‘costs’]) == list, f"Wrong type for d[‘costs’]. {type(d[‘costs’])} != list"
128 assert len(d[‘costs’]) == 1, f"Wrong length for d[‘costs’]. {len(d[‘costs’])} != 1"
→ 129 assert np.allclose(d[‘costs’], expected_output[‘costs’]), f"Wrong values for d[‘costs’]. {d[‘costs’]} != {expected_output[‘costs’]}"
130
131 assert type(d[‘w’]) == np.ndarray, f"Wrong type for d[‘w’]. {type(d[‘w’])} != np.ndarray"

AssertionError: Wrong values for d[‘costs’]. [array(0.15900538)] != [array(0.69314718)]

If all your previous functions pass their test cases, then the bug is that you are calling them incorrectly from model. The first thing to check is that you are not “over-riding” any of the parameters like learning rate and number of iterations when you call optimize from model: there should be no equal signs in any of the parameters you are passing. And you need to pass them all: if you don’t pass them, that means you are using the default values declared in the definition of optimize, instead of the actual values being requested by the test case.

Also note that the shape of X_train is whatever it is. The test cases do not necessarily use the full size of the 64 x 64 images that we use in the real training.

When we call predict, we pass w, b and X. If we pass X_train, then we get the predictions on the training data. If we pass X_test, then we get the predictions on the test data. Of course the w and b values are the same in both cases, but the accuracy of the results may not be the same. :nerd_face:

1 Like