Course 1 week 4 assignment 2 2 layer and l layer

i am getting this error

[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)

Please read up on unpacking in python.

Hi @Nomish_Kumar, and welcome to the specialization. After reading up on unpacking tuples at Balaji’s suggestion, you will see that the ValueError is indicating that your L_layer_model function is returning too many objects. The call to the function should assign one to parameters and the other to costs.

The simplest way to create the error would be to add extra objects to the return statement in L_layer_model. Perhaps you have three or more to help you diagnose an earlier issue?

To understand a little bit more about tuples, if you called the function as say

my_tuple = two_layer_model(train_x, …)`

rather than

parameters, costs = two_layer_model(train_x, ...),

my_tuple should be a two-dimensional tuple with the first element being the parameters object, and the second being the costs object.

still cant understand what are the problem can someone explain for me am going crazy i know its something small but i cant see it any more

I explained the problem on the other thread on which you posted this question. The problem is that you have copied an old version of the function template. They changed the definition of the top level “model” functions in April 2021, so it doesn’t work to copy an old version. It’s also cheating if it’s not your own work. Please start with a clean copy of the notebook to get the correct definition of the functions. You may be able to copy over some of your work from the “YOUR CODE HERE” sections, but even there you have to be careful to notice any changes required between your old code and the new way things work. See the link I gave for more instructions.

am just re taking the course after along time of stopping and had mu own copy for my reference thank you very much i will try to reopen new version

I’m glad to hear it was your own code from a while ago. You can use most of your own code from the “YOUR CODE HERE” sections, but even there some of the function definitions may have changed. Read the instructions in the new notebook carefully and compare to your old code before doing any “copy/paste” from the old version.

1 Like