Week 3 Assignment, forward propagation assertion error

Hello,
I am stuck in exercise 4 of the week 3 assignment . The part where you compute forward propagation. I computed the values using the formula given, using np.dot for Z1 and Z2 without transposing the W1 or W2. A1 and A2 were calculated using the tanh and sigmoid functions repeatedly. I get assertion error , but it says that all tests were passed. Heres the traceback.


AssertionError Traceback (most recent call last)
in
1 t_X, parameters = forward_propagation_test_case()
----> 2 A2, cache = forward_propagation(t_X, parameters)
3 print("A2 = " + str(A2))
4
5 forward_propagation_test(forward_propagation)

in forward_propagation(X, parameters)
37 # YOUR CODE ENDS HERE
38
—> 39 assert(A2.shape == (1, X.shape[1]))
40
41 cache = {“Z1”: Z1,

AssertionError:

Expected output

A2 = [[0.21292656 0.21274673 0.21295976]]
All tests passed!
All tests passed.

Hi, Kiran Shekhar.

Hope that you have followed the given instructions in the notebook:


and have not hard-wired any values? Hard-coding values will refrain from giving you the desired output.

First of all,

I get assertion error , but it says that all tests were passed

Actually, it is not.

Expected output
A2 = [[0.21292656 0.21274673 0.21295976]]
All tests passed!
 All tests passed.

The above is a comment described in a cell as the “expected output”, not your output.

As an assertion says, you have a fundamental error in “A2.shape”. And, this assertion is not in a test program, but in your assignment as follows.

 # YOUR CODE ENDS HERE
   assert(A2.shape == (1, X.shape[1]))    
    cache = {"Z1": Z1,
             "A1": A1,
             "Z2": Z2,
             "A2": A2}
   return A2, cache

So, at first, please check the shape of A2, which should be equal to (1, X.shape[1]) as an assertion checks.

Dot product for Z1 and Z2 seem to be OK.
Tracking the dimension of variables is the common way of debugging that you will use multiple times through this course. You can check the shape of each variable with print() command.
Here is the list of dimensions for key variables for the first test.

W1.shape = (4,2), X.shape = (2,3)
Z1.shape = (4,3)
W2.shape =(1,4), A1.shape = (4,3)
Z2.shape = (1,3)
A2.shape = (1,3)

There was an error in my code, I was doing sigmoid of z1 instead of z2 , my bad. I am sorry, I feel stupid.

OK, good to know. Please go ahead !