Week 2 programming assignment. 6.2. Mini-batch Gradient Descent with Momentum key error

in model(X, Y, layers_dims, optimizer, learning_rate, mini_batch_size, beta, beta1, beta2, epsilon, num_epochs, print_cost)
34 pass # no initialization required for gradient descent
35 elif optimizer == “momentum”:
—> 36 v = initialize_velocity(parameters)
37 elif optimizer == “adam”:
38 v, s = initialize_adam(parameters)

KeyError: ‘dW3’

This is the output for when my momentum function is called. Both 6.1 - Mini-batch Gradient descent and 6.3 - Mini-batch with Adam work as expected. I did not provide the next output in the error because it contains my source code. Have I made a mistake?

Edit: I fixed it. I had written the initialization to pull the matrix size from ‘grads’ and not ‘parameters’. The tests were still passed in the code with the error.

Thank you,
Ryan Johnson

Hi,@rwjohnson42.

Glad you found the problem.

If you don’t mind, I’ll ask you for the code to see if there’s something wrong with the tests.

Thank you for sharing the solution :slight_smile: