Week 3 Lab, part 5, 'Test the Model' Feedback

Getting this error:

AttributeError: ‘numpy.ndarray’ object has no attribute ‘get’

from


AttributeError Traceback (most recent call last)
in
1 parameters, t_X = predict_test_case()
2
----> 3 predictions = predict(parameters, t_X)
4 print("Predictions: " + str(predictions))
5

in predict(parameters, X)
18 # predictions = …
19 # YOUR CODE STARTS HERE
—> 20 A2, cache = forward_propagation(parameters, X)
21 predictions = (A2 > .5)
22

in forward_propagation(X, parameters)
30 # YOUR CODE STARTS HERE
31
—> 32 W1 = parameters.get(‘W1’)
33 b1 = parameters.get(‘b1’)
34 W2 = parameters.get(‘W2’)

In case it helps, I got this error because the parameters of forward_propogation and the predict in the lab are flipped. Definitely my fault and I fixed it with debugging but doesn’t make sense to do:

forward_propogation(X, parameters)

and then

predict(parameters, X)

unless there is and I am too inexperienced to appreciate it. If that’s the case, I would be grateful for an explanation about how this is a good practice.

1 Like

The design of APIs is to some degree a matter of taste and style. There is no general reason to expect that if they take the same parameters that they will take them in the same order. I’m just guessing here, but when they designed the forward propagation API, they thought that the X value was more “important” than the parameters value, because X is the input data. In that case, the parameters are just randomly initialized and we are going to learn them. So their thinking was probably X is the input and parameters are being learned, so it makes more sense to use that order. But as mentioned, this is just “style” and you could argue it the other way as well.

Then in the predict API, the parameters are in some sense “more important”, because those are the “model” that we have learned and we can make predictions on different input datasets, like X_train or X_test, so the makes sense to put the parameters first in that case.

It is essential that we understand the definition of any API that we are going to call. You can’t make assumptions: you have to read and understand the definition. The set of APIs we need to deal with are going to get way more complicated when we get to using TensorFlow in DLS Course 2, so it’s a good idea to build that habit now.

2 Likes

That’s helpful, thank you!

And I can’t wait for course 2!

1 Like