Hi there,
I am getting this kind of output while solving the exercise 5. The answer i am getting is right but it says that 0 tests passed.
Please take a look at the screenshot of the error and provide me suggestions.
Thanks!
Hi there,
I am getting this kind of output while solving the exercise 5. The answer i am getting is right but it says that 0 tests passed.
Please take a look at the screenshot of the error and provide me suggestions.
Thanks!
Well, what i can tell you from the error is that the output of L_model_forward is not a list it says, so I would go back to that function and check what is returning. It needs to be a numpy list.
Hi gent,
Thanks a lot !
So what I tried to print the type of AL(ALtype), the type of cache (cache’type)and the type of caches(caches’type).
Here you can see all this.
So AL is fine .
cache is tuple that is fine too as we have got tuple from previous exercise for cache. So after applying in the function we should get here tuple as well (function linear_activation_forward)
→ Now comes the caches’type this is the nonetype unfortunately . I dont understand it .
As we have declared caches as list and then we are appending tuples in it
So it should not be a problem in that case.
I tried to understand this but don’t think I would be able to resolve the issue as everything seems fine for me in this code. Do you have any suggestion here ?
Please realize that there are two separate tests there:
One that produces the AL
value there in the cell.
A different test from the file public_tests.py
.
It is the second test that is failing, but notice that there is something wrong even with the first test: you should not be returning “None” for any cache
values. So it looks like your logic for handling the cache is wrong for the “output” layer. That’s the one outside the “for” loop.
Also note that it is caches
, not cache
, that is None
. So maybe your “append” logic is wrong.
Also note that the first test has 2 hidden layers, so there should be a total of 3 cache
values for the individual layers that all get appended to the overall caches
list, right? But we see only one each of the print statements. Where did you put that? You might want to print the cache type every time you touch it. Also print the layer numbers so that you get a clearer picture of what is going on.
Hi paulinpaloalto,
Thanks a lot for your valuable suggestions. It helped me understand to understand the whole picture.
Here I tried to print layers wise cache and array. It seems me that caches ( as I am unable to print indices values for it as its returning me error of kind that its a nonetype object".
Well, I have put here my output and please let me know where I have done wrong as logic of my Output layer seems me right. The thing is there we need not to write a lot of code as its only one line that I am printing here.
’ AL, cache = linear_activation_forward(A,parameters[‘W’ + str(L)], parameters[‘b’ + str(L)],‘sigmoid’)’
layer= 1
cache = ((array([[-0.31178367, 0.72900392, 0.21782079, -0.8990918 ],
[-2.48678065, 0.91325152, 1.12706373, -1.51409323],
[ 1.63929108, -0.4298936 , 2.63128056, 0.60182225],
[-0.33588161, 1.23773784, 0.11112817, 0.12915125],
[ 0.07612761, -0.15512816, 0.63422534, 0.810655 ]]), array([[ 0.35480861, 1.81259031, -1.3564758 , -0.46363197, 0.82465384],
[-1.17643148, 1.56448966, 0.71270509, -0.1810066 , 0.53419953],
[-0.58661296, -1.48185327, 0.85724762, 0.94309899, 0.11444143],
[-0.02195668, -2.12714455, -0.83440747, -0.46550831, 0.23371059]]), array([[ 1.38503523],
[-0.51962709],
[-0.78015214],
[ 0.95560959]])), array([[-5.23825714, 3.18040136, 0.4074501 , -1.88612721],
[-2.77358234, -0.56177316, 3.18141623, -0.99209432],
[ 4.18500916, -1.78006909, -0.14502619, 2.72141638],
[ 5.05850802, -1.25674082, -3.54566654, 3.82321852]]))
cache’type <class ‘tuple’>
layer= 2
cache = ((array([[0. , 3.18040136, 0.4074501 , 0. ],
[0. , 0. , 3.18141623, 0. ],
[4.18500916, 0. , 0. , 2.72141638],
[5.05850802, 0. , 0. , 3.82321852]]), array([[-0.12673638, -1.36861282, 1.21848065, -0.85750144],
[-0.56147088, -1.0335199 , 0.35877096, 1.07368134],
[-0.37550472, 0.39636757, -0.47144628, 2.33660781]]), array([[ 1.50278553],
[-0.59545972],
[ 0.52834106]])), array([[ 2.2644603 , 1.09971298, -2.90298027, 1.54036335],
[ 6.33722569, -2.38116246, -4.11228806, 4.48582383],
[10.37508342, -0.66591468, 1.63635185, 8.17870169]]))
cache’type <class ‘tuple’>
layer= 3
AL’type [[0.03921668 0.70498921 0.19734387 0.04728177]] <class ‘numpy.ndarray’>
cache’type ((array([[ 2.2644603 , 1.09971298, 0. , 1.54036335],
[ 6.33722569, 0. , 0. , 4.48582383],
[10.37508342, 0. , 1.63635185, 8.17870169]]), array([[ 0.9398248 , 0.42628539, -0.75815703]]), array([[-0.16236698]])), array([[-3.19864676, 0.87117055, -1.40297864, -3.00319435]])) <class ‘tuple’>
caches’type None <class ‘NoneType’>
AL = [[0.03921668 0.70498921 0.19734387 0.04728177]]
layer= 1
cache = ((array([[-0.31178367, 0.72900392, 0.21782079, -0.8990918 ],
[-2.48678065, 0.91325152, 1.12706373, -1.51409323],
[ 1.63929108, -0.4298936 , 2.63128056, 0.60182225],
[-0.33588161, 1.23773784, 0.11112817, 0.12915125],
[ 0.07612761, -0.15512816, 0.63422534, 0.810655 ]]), array([[ 0.35480861, 1.81259031, -1.3564758 , -0.46363197, 0.82465384],
[-1.17643148, 1.56448966, 0.71270509, -0.1810066 , 0.53419953],
[-0.58661296, -1.48185327, 0.85724762, 0.94309899, 0.11444143],
[-0.02195668, -2.12714455, -0.83440747, -0.46550831, 0.23371059]]), array([[ 1.38503523],
[-0.51962709],
[-0.78015214],
[ 0.95560959]])), array([[-5.23825714, 3.18040136, 0.4074501 , -1.88612721],
[-2.77358234, -0.56177316, 3.18141623, -0.99209432],
[ 4.18500916, -1.78006909, -0.14502619, 2.72141638],
[ 5.05850802, -1.25674082, -3.54566654, 3.82321852]]))
cache’type <class ‘tuple’>
layer= 2
cache = ((array([[0. , 3.18040136, 0.4074501 , 0. ],
[0. , 0. , 3.18141623, 0. ],
[4.18500916, 0. , 0. , 2.72141638],
[5.05850802, 0. , 0. , 3.82321852]]), array([[-0.12673638, -1.36861282, 1.21848065, -0.85750144],
[-0.56147088, -1.0335199 , 0.35877096, 1.07368134],
[-0.37550472, 0.39636757, -0.47144628, 2.33660781]]), array([[ 1.50278553],
[-0.59545972],
[ 0.52834106]])), array([[ 2.2644603 , 1.09971298, -2.90298027, 1.54036335],
[ 6.33722569, -2.38116246, -4.11228806, 4.48582383],
[10.37508342, -0.66591468, 1.63635185, 8.17870169]]))
cache’type <class ‘tuple’>
layer= 3
AL’type [[0.03921668 0.70498921 0.19734387 0.04728177]] <class ‘numpy.ndarray’>
cache’type ((array([[ 2.2644603 , 1.09971298, 0. , 1.54036335],
[ 6.33722569, 0. , 0. , 4.48582383],
[10.37508342, 0. , 1.63635185, 8.17870169]]), array([[ 0.9398248 , 0.42628539, -0.75815703]]), array([[-0.16236698]])), array([[-3.19864676, 0.87117055, -1.40297864, -3.00319435]])) <class ‘tuple’>
caches’type None <class ‘NoneType’>
Error: The function should return a numpy array. in variable 1. Got type: <class ‘NoneType’> but expected type <class ‘list’>
layer= 1
cache = ((array([[-0.31178367, 0.72900392, 0.21782079, -0.8990918 ],
[-2.48678065, 0.91325152, 1.12706373, -1.51409323],
[ 1.63929108, -0.4298936 , 2.63128056, 0.60182225],
[-0.33588161, 1.23773784, 0.11112817, 0.12915125],
[ 0.07612761, -0.15512816, 0.63422534, 0.810655 ]]), array([[ 0.35480861, 1.81259031, -1.3564758 , -0.46363197, 0.82465384],
[-1.17643148, 1.56448966, 0.71270509, -0.1810066 , 0.53419953],
[-0.58661296, -1.48185327, 0.85724762, 0.94309899, 0.11444143],
[-0.02195668, -2.12714455, -0.83440747, -0.46550831, 0.23371059]]), array([[ 1.38503523],
[-0.51962709],
[-0.78015214],
[ 0.95560959]])), array([[-5.23825714, 3.18040136, 0.4074501 , -1.88612721],
[-2.77358234, -0.56177316, 3.18141623, -0.99209432],
[ 4.18500916, -1.78006909, -0.14502619, 2.72141638],
[ 5.05850802, -1.25674082, -3.54566654, 3.82321852]]))
cache’type <class ‘tuple’>
layer= 2
cache = ((array([[0. , 3.18040136, 0.4074501 , 0. ],
[0. , 0. , 3.18141623, 0. ],
[4.18500916, 0. , 0. , 2.72141638],
[5.05850802, 0. , 0. , 3.82321852]]), array([[-0.12673638, -1.36861282, 1.21848065, -0.85750144],
[-0.56147088, -1.0335199 , 0.35877096, 1.07368134],
[-0.37550472, 0.39636757, -0.47144628, 2.33660781]]), array([[ 1.50278553],
[-0.59545972],
[ 0.52834106]])), array([[ 2.2644603 , 1.09971298, -2.90298027, 1.54036335],
[ 6.33722569, -2.38116246, -4.11228806, 4.48582383],
[10.37508342, -0.66591468, 1.63635185, 8.17870169]]))
cache’type <class ‘tuple’>
layer= 3
AL’type [[0.03921668 0.70498921 0.19734387 0.04728177]] <class ‘numpy.ndarray’>
cache’type ((array([[ 2.2644603 , 1.09971298, 0. , 1.54036335],
[ 6.33722569, 0. , 0. , 4.48582383],
[10.37508342, 0. , 1.63635185, 8.17870169]]), array([[ 0.9398248 , 0.42628539, -0.75815703]]), array([[-0.16236698]])), array([[-3.19864676, 0.87117055, -1.40297864, -3.00319435]])) <class ‘tuple’>
caches’type None <class ‘NoneType’>
Error: Wrong shape for variable 0.
Error: Wrong shape for variable 1.
Error: Wrong shape for variable 2.
layer= 1
cache = ((array([[-0.31178367, 0.72900392, 0.21782079, -0.8990918 ],
[-2.48678065, 0.91325152, 1.12706373, -1.51409323],
[ 1.63929108, -0.4298936 , 2.63128056, 0.60182225],
[-0.33588161, 1.23773784, 0.11112817, 0.12915125],
[ 0.07612761, -0.15512816, 0.63422534, 0.810655 ]]), array([[ 0.35480861, 1.81259031, -1.3564758 , -0.46363197, 0.82465384],
[-1.17643148, 1.56448966, 0.71270509, -0.1810066 , 0.53419953],
[-0.58661296, -1.48185327, 0.85724762, 0.94309899, 0.11444143],
[-0.02195668, -2.12714455, -0.83440747, -0.46550831, 0.23371059]]), array([[ 1.38503523],
[-0.51962709],
[-0.78015214],
[ 0.95560959]])), array([[-5.23825714, 3.18040136, 0.4074501 , -1.88612721],
[-2.77358234, -0.56177316, 3.18141623, -0.99209432],
[ 4.18500916, -1.78006909, -0.14502619, 2.72141638],
[ 5.05850802, -1.25674082, -3.54566654, 3.82321852]]))
cache’type <class ‘tuple’>
layer= 2
cache = ((array([[0. , 3.18040136, 0.4074501 , 0. ],
[0. , 0. , 3.18141623, 0. ],
[4.18500916, 0. , 0. , 2.72141638],
[5.05850802, 0. , 0. , 3.82321852]]), array([[-0.12673638, -1.36861282, 1.21848065, -0.85750144],
[-0.56147088, -1.0335199 , 0.35877096, 1.07368134],
[-0.37550472, 0.39636757, -0.47144628, 2.33660781]]), array([[ 1.50278553],
[-0.59545972],
[ 0.52834106]])), array([[ 2.2644603 , 1.09971298, -2.90298027, 1.54036335],
[ 6.33722569, -2.38116246, -4.11228806, 4.48582383],
[10.37508342, -0.66591468, 1.63635185, 8.17870169]]))
cache’type <class ‘tuple’>
layer= 3
AL’type [[0.03921668 0.70498921 0.19734387 0.04728177]] <class ‘numpy.ndarray’>
cache’type ((array([[ 2.2644603 , 1.09971298, 0. , 1.54036335],
[ 6.33722569, 0. , 0. , 4.48582383],
[10.37508342, 0. , 1.63635185, 8.17870169]]), array([[ 0.9398248 , 0.42628539, -0.75815703]]), array([[-0.16236698]])), array([[-3.19864676, 0.87117055, -1.40297864, -3.00319435]])) <class ‘tuple’>
caches’type None <class ‘NoneType’>
Error: Wrong output for variable 0.
Error: Wrong output for variable 1.
Error: Wrong output for variable 2.
Error: Wrong output for variable 1.
0 Tests passed
3 Tests failed
It looks like your cache value for each individual layer is correct: it is a 2-tuple, but the only problem is the caches
list or array. That is turning out to be type “None”. So I think the most likely place to look for the problem is where you append the “layer” cache
entry to caches
. Note that the template code initializes caches
as an empty list. A “list” object in python has an “append()
” method. But it’s critical to realize that there are no “assignment statements” involved in invoking the append method. I’ll bet your code says something like this:
caches = caches.append(cache)
That is an error, because it means you are assigning the output (return value) of the append call to caches
. But the append method does not return any return value, which is why you end up with “None” as the value of caches
.
If I have a list called myList
and I want to append newElement
to it, the syntax is:
myList.append(newElement)
That is what I mean by no assignment statement involved.
Thanks a ton!
This was a very little mistake and I was unable to catch it
Best Regards,
Sadhana