Week 4 assignment deep neural network application

hello i used the codes correctly it is still showing error and my assignment is not passed . please help me out .
error i am getting is :
ValidateApp | INFO] Validating ‘/home/jovyan/work/submitted/courseraLearner/W4A2/Deep Neural Network - Application.ipynb’
[ValidateApp | INFO] Executing notebook with kernel: python3
[ValidateApp | ERROR] Timeout waiting for execute reply (30s).
[ValidateApp | ERROR] Interrupting kernel
[ValidateApp | ERROR] Timeout waiting for execute reply (30s).
[ValidateApp | ERROR] Interrupting kernel
Tests failed on 2 cell(s)! These tests could be hidden. Please check your submission.

The following cell failed:

parameters, costs = two_layer_model(train_x, train_y, layers_dims = (n_x, n_h, n_y)...

print("Cost after first iteration: " + str(costs[0]))

two_layer_model_test(two_layer_model)

The error was:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-8-f9ec5304d38d> in <module>
----> 1 parameters, costs = two_layer_model(train_x, train_y, layers_dims = (n_x, n...
      2 
      3 print("Cost after first iteration: " + str(costs[0]))
      4 
      5 two_layer_model_test(two_layer_model)

ValueError: too many values to unpack (expected 2)

==========================================================================================
The following cell failed:

parameters, costs = L_layer_model(train_x, train_y, layers_dims, num_iterations = 1...

print("Cost after first iteration: " + str(costs[0]))

L_layer_model_test(L_layer_model)

The error was:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-14-d5e7eb27c0fc> in <module>
----> 1 parameters, costs = L_layer_model(train_x, train_y, layers_dims, num_iterat...
      2 
      3 print("Cost after first iteration: " + str(costs[0]))
      4 
      5 L_layer_model_test(L_layer_model)

ValueError: too many values to unpack (expected 2)

what does this mean can someone help me out soon

Note: I’m on v8 of the assignment.

The function two_layer_model and L_layer_model returns only a single variable parameters. So you cannot unpack/assign the function to 2 variables. Try removing the costs variable while calling the function.

hi can you please help me out how do i remove cost variable few cells are not modifiable in the notebook. plz help soon

Ah we’re on different versions. I thought you had modified them. Lemme try to to move to the newer version.

yes please can you help me out soon . thank you :slight_smile: i have been sleepless trying to figure out what is wrong

1 Like

Hi @h_M could it be that you changed the return statement of the two_layer_model function?
It should be returning both parameters and cost:

def two_layer_model(X, Y, layers_dims, 
                  learning_rate = 0.0075, num_iterations = 3000, 
                  print_cost=False):
     ....
     ....
     return parameters, costs
1 Like

hello sir i tried with your input its showing this error
File “”, line 94
return parameters, costs
^
IndentationError: unexpected indent

Hi @h_M maybe there are some lines not well indented (as python mandates) before the return statement? For example a line of the function with no indentation at all?

1 Like

dear @h_M it is not allowed to post solution code of the assignement in the forum, I kindly ask you to remove the graded code part. Thanks

1 Like

my apologies sir
can you please help me with the assignment i am really stuck i have no clue what is going on

dear @h_M I think your problem is that you have changed the final part of the cell that contains the function two layer model. Probably you missdeleted some lines.

The original (it is not the graded part of the function) finish like this, be super careful with indentation:

        # Print the cost every 100 training example
        if print_cost and i % 100 == 0 or i == num_iterations - 1:
            print("Cost after iteration {}: {}".format(i, np.squeeze(cost)))
        if i % 100 == 0 or i == num_iterations:
            costs.append(cost)

    return parameters, costs

def plot_costs(costs, learning_rate=0.0075):
    plt.plot(np.squeeze(costs))
    plt.ylabel('cost')
    plt.xlabel('iterations (per hundreds)')
    plt.title("Learning rate =" + str(learning_rate))
    plt.show()

hello sir which line of code is this for ?
L layer model ? or two layer model . i am getting errors in both.

I suggest to check both of them

okay sir please give me two mins i will surely get back to you . thank you

NameError Traceback (most recent call last)
in
----> 1 parameters, costs = two_layer_model(train_x, train_y, layers_dims = (n_x, n_h, n_y), num_iterations = 2, print_cost=False)
2
3 print("Cost after first iteration: " + str(costs[0]))
4
5 two_layer_model_test(two_layer_model)

NameError: name ‘train_x’ is not defined
sir when i check the next cell which is not modified it is showing this error hence the same problems next cells are not showing results

please note
the version of the notebook server is: 6.0.3

Hi @h_M it seems you have not run the cell where train_x is defined

1 Like

Hi, @RolandSherwin.

Please note this means you are on the old version of the course, even though you are on Discourse. So your results may not match what we see on the new version of the course.

1 Like

Sir I have a problem in the same step. This is the error:


IndexError Traceback (most recent call last)
in
1 parameters, costs = two_layer_model(train_x, train_y, layers_dims = (n_x, n_h, n_y), num_iterations = 2, print_cost=False)
2
----> 3 print("Cost after first iteration: " + str(costs[0]))
4
5 two_layer_model_test(two_layer_model)

IndexError: list index out of range

That error means that the costs array returned by your two_layer_model function must be an empty list. So how could that happen? With 2 iterations, you should have returned one cost value for iteration 0, right?

Are you sure you didn’t copy over the template code from the previous version of the course? Here’s what the template code should look like for the last section of the two_layer_model function:

        # Print the cost every 100 training example
        if print_cost and i % 100 == 0 or i == num_iterations - 1:
            print("Cost after iteration {}: {}".format(i, np.squeeze(cost)))
        if i % 100 == 0 or i == num_iterations:
            costs.append(cost)

    return parameters, costs

In the old version of the notebook from the previous course, the costs are not added to the array if print_cost is False, as it is in the test case in question here. You can’t just copy over everything from the previous course without looking. It gets you in trouble in some ways, e.g. this example.

1 Like