Course 1 Week 4 Exercise 9 : ValueError: not enough values to unpack (expected 3, got 2)

Hello Team,

I have received following Value Error in Course 1 Week 4 Exercise 9:
ValueError Traceback (most recent call last)
in
1 t_AL, t_Y_assess, t_caches = L_model_backward_test_case()
----> 2 grads = L_model_backward(t_AL, t_Y_assess, t_caches)
3
4 print("dA0 = " + str(grads[‘dA0’]))
5 print("dA1 = " + str(grads[‘dA1’]))

in L_model_backward(AL, Y, caches)
47 # YOUR CODE STARTS HERE
48 current_cache = caches[L-1]
—> 49 dA_prev_temp, dW_temp, db_temp = linear_backward(dAL,current_cache)
50 grads[“dA” + str(L-1)] = dA_prev_temp
51 grads[“dW” + str(L)] = dW_temp

in linear_backward(dZ, cache)
14 db – Gradient of the cost with respect to b (current layer l), same shape as b
15 “”"
—> 16 A_prev, W, b = cache
17 m = A_prev.shape[1]
18 #print(dZ)

ValueError: not enough values to unpack (expected 3, got 2)

In the code snippet the length = 2 (Variable L) which is equal to length of “caches”
I am passing current_cache parameter to function linear_backward(dAL,current_cache) where current_cache = caches[L-1]

i tried to resolve this error but unfortunately not succeed.
Any help is much appreciated.

Thanks in advance.
Abhay

Hi @Abhay25 ,

In this part of the code, the starting layer is the output layer where the activation function is ‘sigmoid’ because we are working backward from the output layer to the first hidden layer.

Your code calling linear_backward() is incorrect, it should be linear_activation_backward(), with 3 parameters, where the last one is to specify which activation to use.

Thank you for your inputs.
But this solution is not resolved the issue. :slightly_frowning_face:

Hi @Abhay25 ,

What have you changed and what error output do you have? It would help to diagnose the problem if you could give us more information.

I have done some improvement in the previously reported issue.


Returned outputs are incorrect values.
I am trying to find the solution.
Please guide me.

Thanks,
Abhay

Hello all,

Issue resolved.
I forget the minus sign in
dAL = - (np.divide(Y, AL) - np.divide(1 - Y, 1 - AL))

regards,
Abhay

Hi @Abhay25 ,

Great to hear you have solved the problem. Thanks for letting us know.

1 Like