Course 1 week 4 assignment 2, Shape not aligned error

ValueError                                Traceback (most recent call last)
<ipython-input-25-f9ec5304d38d> in <module>
----> 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)

<ipython-input-24-3411aa4b99ea> in two_layer_model(X, Y, layers_dims, learning_rate, num_iterations, print_cost)
     47         # YOUR CODE STARTS HERE
     48         A1, cache1 = linear_activation_forward(X, W1, b1, activation = "relu")
---> 49         A2, cache2 = linear_activation_forward(X, W2, b2, activation = "sigmoid")
     50         # YOUR CODE ENDS HERE
     51 

~/work/release/W4A2/dnn_app_utils_v3.py in linear_activation_forward(A_prev, W, b, activation)
    201     if activation == "sigmoid":
    202         # Inputs: "A_prev, W, b". Outputs: "A, activation_cache".
--> 203         Z, linear_cache = linear_forward(A_prev, W, b)
    204         A, activation_cache = sigmoid(Z)
    205 

~/work/release/W4A2/dnn_app_utils_v3.py in linear_forward(A, W, b)
    176     """
    177 
--> 178     Z = W.dot(A) + b
    179 
    180     assert(Z.shape == (W.shape[0], A.shape[1]))

ValueError: shapes (1,7) and (12288,209) not aligned: 7 (dim 1) != 12288 (dim 0)

Please I am getting the above error in one of my code. I don’t know what I am doing wrong. Kindly help.

The error is pretty clear if you just follow the exception trace: you are passing the wrong value as the A_prev input for the second layer. It’s supposed to be the output of the previous layer. That’s the whole point of forward propagation, right? :nerd_face:

1 Like

Oh yea…I figured that out… :smiley: Thanks