Course 1 Week 4 Assignment 2 : don't know what's wrong

[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
Tests failed on 1 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]))


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...
      3 print("Cost after first iteration: " + str(costs[0]))
      5 two_layer_model_test(two_layer_model)

<ipython-input-7-d7ef38fd4361> in two_layer_model(X, Y, layers_dims, learning_rate,...
     78         # Update parameters.
     79         #(approx. 1 line of code)
---> 80         parameters = update_parameters(parameters, grads, learning_rate)
     81         # YOUR CODE STARTS HERE

~/work/submitted/courseraLearner/W4A2/ in update_parameters(para...
    378     # Update rule for each parameter. Use a for loop.
    379     for l in range(L):
--> 380         parameters["W" + str(l+1)] = parameters["W" + str(l+1)] - learning_...
    381         parameters["b" + str(l+1)] = parameters["b" + str(l+1)] - learning_...

ValueError: operands could not be broadcast together with shapes (7,12288) (1,7)

The right side of the equation for parameter update should have the same shape. This is just multiplying each weight for the layer under consideration with learning rate for an update. If that’s the case, please click my name and message your notebook as an attachment.

That type of error most likely means you are referencing global variables somewhere in your two_layer_model logic, instead of the actual local variables that are relevant. The key point is that the bug is in your new top layer logic, not in the function that is actually throwing the error. The problem is you passed down bad arguments to the lower level function. Your mission is to figure out how that happened … :nerd_face:

There are multiple possibilities, of course. Both Balaji and Paul should be right.
With looking at the shape, the most possible case is you mixed up dW1 and dW2 (and db1 and db2).
As Balaji suggested, W1 and dW1 needs to be the same shape. (and W2 and dW2 are as well.)
As “W1”/“W2” are updated inside update_parameters(), most possible error in your code is dW1/dW2.

Of course, the above is just one of possibilities. It is better for you to check dimensions of W, and dW step-by-step.

1 Like

@Akhilesh19Sharma Please fix the 2nd step in backward propagation (i.e. for the relu step).

1 Like