Error about initialize_parameters_deep in Week4 assignment 1

Dear Gents ,

Can anyone support to fix this issue

{moderator edit - solution code removed}

Please don’t post solution code on a public thread. The best way to ask this kind of question is to show us the error output that you get from running the test cell for the function in question.

Your logic is incorrect. There should be no need for any “if” statements in the body of the “for” loop: it gets executed once for each value of l. Note that this code is general, meaning that it should work for any number of layers in the network. Your logic tries to handle both layer 1 and layer 2 in the first iteration of the loop and then any further values of l will be ignored, right?

Also notice that you have to be careful about the difference between l (lower case letter “ell”) and 1 (the number one). They look very similar in the font used by the notebooks and it looks like you’ve used 1 in at least one place (pun intended) in which l was intended.

1 Like

Salam Paul,
Sure we will post only error output,Yes the logic was incorrect actually i was trying to understand range(1,L) and how can be L=3 but we have only 2 Iterations , I Think should be 3 instead 2 due to from range loop start from 1 to 3 strange and b1 and b2 not changing(same shape every time).
I know also that [5,4,3] we have input layer=5 and 1 hidden layer with 4 unit and 1 output layer with 3 unit.
but i’m confusing how can 1 output with 3 units, i tried to draw the NN in paper it’s figure out instead 3 might we put 1 output layer and 1 unit .please your support to understand why we have 3 units ?

please check below issue and sorry for late reply i had many tasks from my company

A very basic thing to understand about python is that all indexing is “zero based”. So if you have a list or an array with 5 elements, the index of the first element is 0 and the last is 4, right? It works the same for “for” loops. Try writing this loop and watch what happens:

for ii in range(5):
    print(f"ii = {ii}")

print(f"After loop ii = {ii}")

Of course here we have range(1, L). So try that:

for ii in range(1, 4):
    print(f"ii = {ii}")

print(f"After loop ii = {ii}")

This is just a test case to make sure that your code is general and can handle any case. We actually will have only one output unit in the real network we are building here, because we are doing binary classification. But later in Course 2 and the later courses we will see more advanced cases in which we are doing multiclass classification (not just “cat” or “not a cat”, but cat, dog, zebra, koala, elephant or aardvark). In those cases the number of output neurons will be greater than 1. So our initialization routine would be able to handle those cases as well when we get there, even though it is more powerful than we really need here.

2 Likes

Dear Paul,
I got your point and thank you for all explanations, But b1 and b2 shapes are the same which’s wrong, Could you support to fix it?

Well, what dimension do you set for b^{[l]}? Are you sure you used the dimension from layer l as opposed to layer 1? In the font that the notebook uses, 1 and l are pretty easy to confuse, as I pointed out on my earlier reply on this thread.

now i have another issue, i believe this notebook has been come lots of mistake and i can’t fix from where getting this issue .

{moderator edit - solution code removed}

It looks like you modified that last assertion statement so that it is missing a close parenthesis. That’s why you get the syntax error.

Thank you Paul you are my hero ,finally i can move on into the next exercise

Salam Paul,
could you please explain what the benefits for those files bellow ?because i want to understand but i can’t understood .
dnn?
test_utils?
public_test ?
test_Cases?

Hello @Mohamad_Omar,

Those .py files contain helper functions that are used by the lab. For example, in your screenshot in this reply, this function → image should be defined in one of those .py files.

For example, you can define the following function and save it in a whatever_name.py:

def sum(a, b):
    return a + b

and then you might compute 3 plus 4 in the lab like:

from whatever_name import sum

print('answer is: ', sum(3, 4))

Above is the idea behind but of course the functions in those files are more complicated, however, those files have to be there in order for the lab to find and use the functions, and that is why you can find them.

Since the purpose of the lab is to demo and practice core deep learning skills, we only see explanations for the code in the lab, but not for the helper functions in those .py files. In fact, you may not ever reuse, for example, any testing code there unless you are creating a course on Cousera. :wink:

Cheers,
Raymond

1 Like

Hi @rmwkwok,

Thank you, i got your point no need to focus of them, only we need to do the lab exam by sequence

1 Like

Yes, as Raymond says, those files contain functions that are “imported” by the main notebook and then called. You can examine the contents of any of those files by clicking “File → Open” and then selecting that file. In some cases they use more sophisticated python syntax than we need in the main notebook, so it can be educational to read that code on several levels. :nerd_face:

One case in which that might be helpful is when you fail a test case that is an imported function from public_tests.py. Perhaps understanding exactly what the test is doing will shed some light on what the problem is in your code.

1 Like

Hi @paulinpaloalto

Thank you for reply …

That’s a very good point about checking out the tests. Thanks Paul!

Dear @rmwkwok @paulinpaloalto

please i can’t figure out where is the issue please just a hint for continuing

You are “mixing metaphors” there by using both dot products and elementwise multiply in your cost computation. It’s better to be consistent. Also note that on the dot product computation for the y = 1 case, it matters which operand you transpose. Please see this thread for more details on that point.

1 Like

Dear @paulinpaloalto

As per the thread , I have Been Transposed Y and Keep np.SUM in Order to get 1 * 1 output. But they keep showing me the bellow error , can you please share your feedback :slight_smile:

You have parenthesis in the wrong locations. One of the sets is interpreted as a function call.

Dear @TMosh

Thank you i fixed the parentheses but still the same error not resolved please check below :slight_smile: