I’ve tried looking out for the error, but couldn’t catch one . Please help me to debug and identify what’s wrong with the code and why is it not passing all the test cases.
CODE :
GRADED FUNCTION: update_parameters_with_momentum
def update_parameters_with_momentum(parameters, grads, v, beta, learning_rate):
“”"
Update parameters using Momentum
Arguments:
parameters -- python dictionary containing your parameters:
parameters['W' + str(l)] = Wl
parameters['b' + str(l)] = bl
grads -- python dictionary containing your gradients for each parameters:
grads['dW' + str(l)] = dWl
grads['db' + str(l)] = dbl
v -- python dictionary containing the current velocity:
v['dW' + str(l)] = ...
v['db' + str(l)] = ...
beta -- the momentum hyperparameter, scalar
learning_rate -- the learning rate, scalar
Returns:
parameters -- python dictionary containing your updated parameters
v -- python dictionary containing your updated velocities
"""
L = len(parameters) // 2 # number of layers in the neural networks
# Momentum update for each parameter
for l in range(1, L + 1):
# (approx. 4 lines)
# compute velocities
# v["dW" + str(l)] = ...
# v["db" + str(l)] = ...
# update parameters
# parameters["W" + str(l)] = ...
# parameters["b" + str(l)] = ...
# YOUR CODE STARTS HERE
v["dW"+str(l)]=beta*v["dW"+str(l)] + (1- beta)*grads['dW'+str(l)]
v["db"+str(l)]=beta*v["db" + str(l)] + (1- beta)*grads['dW'+str(l)]
parameters["W" + str(l)] = parameters["W" + str(l)] - learning_rate*v["dW" + str(l)]
parameters["b" + str(l)] = parameters["b" + str(l)] - learning_rate*v["db" + str(l)]
# YOUR CODE ENDS HERE
return parameters, v
OUTPUT
W1 =
[[ 1.62544598 -0.61290114 -0.52907334]
[-1.07347112 0.86450677 -2.30085497]]
b1 =
[[ 1.74591238 1.74366704 1.74391017]
[-0.7617094 -0.76210776 -0.76052317]]
W2 =
[[ 0.31930698 -0.24990073 1.4627996 ]
[-2.05974396 -0.32173003 -0.38320915]
[ 1.13444069 -1.0998786 -0.1713109 ]]
b2 =
[[-0.87759053 -0.87838877 -0.87716676]
[ 0.0426105 0.04290092 0.04305895]
[ 0.58348646 0.58282788 0.58393252]]
v[“dW1”] =
[[-0.11006192 0.11447237 0.09015907]
[ 0.05024943 0.09008559 -0.06837279]]
v[“db1”] =
[[-0.11006192 0.11447237 0.09015907]
[ 0.05024943 0.09008559 -0.06837279]]
v[“dW2”] =
[[-0.02678881 0.05303555 -0.06916608]
[-0.03967535 -0.06871727 -0.08452056]
[-0.06712461 -0.00126646 -0.11173103]]
v[“db2”] = v[[-0.02678881 0.05303555 -0.06916608]
[-0.03967535 -0.06871727 -0.08452056]
[-0.06712461 -0.00126646 -0.11173103]]
1 Tests passed
2 Tests failed
AssertionError Traceback (most recent call last)
in
11 print(“v[“db2”] = v” + str(v[“db2”]))
12
—> 13 update_parameters_with_momentum_test(update_parameters_with_momentum)
~/work/release/W2A1/public_tests.py in update_parameters_with_momentum_test(target)
155 ]
156
→ 157 multiple_test(test_cases, target)
158
159 def initialize_adam_test(target):
/opt/conda/lib/python3.7/site-packages/dlai_tools/testing_utils.py in multiple_test(test_cases, target)
162 print(’\033[91m’, len(test_cases) - success, " Tests failed")
163 raise AssertionError(
→ 164 “Not all tests were passed for {}. Check your equations and avoid using global variables inside the function.”.format(target.name))
AssertionError: Not all tests were passed for update_parameters_with_momentum. Check your equations and avoid using global variables inside the function.W1 =
[[ 1.62544598 -0.61290114 -0.52907334]
[-1.07347112 0.86450677 -2.30085497]]
b1 =
[[ 1.74591238 1.74366704 1.74391017]
[-0.7617094 -0.76210776 -0.76052317]]
W2 =
[[ 0.31930698 -0.24990073 1.4627996 ]
[-2.05974396 -0.32173003 -0.38320915]
[ 1.13444069 -1.0998786 -0.1713109 ]]
b2 =
[[-0.87759053 -0.87838877 -0.87716676]
[ 0.0426105 0.04290092 0.04305895]
[ 0.58348646 0.58282788 0.58393252]]
v[“dW1”] =
[[-0.11006192 0.11447237 0.09015907]
[ 0.05024943 0.09008559 -0.06837279]]
v[“db1”] =
[[-0.11006192 0.11447237 0.09015907]
[ 0.05024943 0.09008559 -0.06837279]]
v[“dW2”] =
[[-0.02678881 0.05303555 -0.06916608]
[-0.03967535 -0.06871727 -0.08452056]
[-0.06712461 -0.00126646 -0.11173103]]
v[“db2”] = v[[-0.02678881 0.05303555 -0.06916608]
[-0.03967535 -0.06871727 -0.08452056]
[-0.06712461 -0.00126646 -0.11173103]]
1 Tests passed
2 Tests failed
AssertionError Traceback (most recent call last)
in
11 print(“v[“db2”] = v” + str(v[“db2”]))
12
—> 13 update_parameters_with_momentum_test(update_parameters_with_momentum)
~/work/release/W2A1/public_tests.py in update_parameters_with_momentum_test(target)
155 ]
156
→ 157 multiple_test(test_cases, target)
158
159 def initialize_adam_test(target):
/opt/conda/lib/python3.7/site-packages/dlai_tools/testing_utils.py in multiple_test(test_cases, target)
162 print(’\033[91m’, len(test_cases) - success, " Tests failed")
163 raise AssertionError(
→ 164 “Not all tests were passed for {}. Check your equations and avoid using global variables inside the function.”.format(target.name))
AssertionError: Not all tests were passed for update_parameters_with_momentum. Check your equations and avoid using global variables inside the function.