Hi, in section 6.1 - Mini-Batch Gradient Descent, when I ran the code block below, I got this error:
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
<ipython-input-85-6c6daf13604b> in <module>
1 # train 3-layer model
2 layers_dims = [train_X.shape[0], 5, 2, 1]
----> 3 parameters = model(train_X, train_Y, layers_dims, optimizer = "gd")
4
5 # Predict
<ipython-input-84-620ef2b96663> in model(X, Y, layers_dims, optimizer, learning_rate, mini_batch_size, beta, beta1, beta2, epsilon, num_epochs, print_cost)
58
59 # Backward propagation
---> 60 grads = backward_propagation(minibatch_X, minibatch_Y, caches)
61
62 # Update parameters
~/work/release/W2A1/opt_utils_v1a.py in backward_propagation(X, Y, cache)
153 gradients -- A dictionary with the gradients with respect to each parameter, activation and pre-activation variables
154 """
--> 155 m = X.shape[1]
156 (z1, a1, W1, b1, z2, a2, W2, b2, z3, a3, W3, b3) = cache
157
IndexError: tuple index out of range
Although all the previous code blocks work fine except for the block
Exercise 2 - random_mini_batches, I got this error:
---------------------------------------------------------------------------
AssertionError Traceback (most recent call last)
<ipython-input-35-2caeb7a27c84> in <module>
11 assert n_batches == math.ceil(m / mini_batch_size), f"Wrong number of mini batches. {n_batches} != {math.ceil(m / mini_batch_size)}"
12 for k in range(n_batches - 1):
---> 13 assert mini_batches[k][0].shape == (nx, mini_batch_size), f"Wrong shape in {k} mini batch for X"
14 assert mini_batches[k][1].shape == (1, mini_batch_size), f"Wrong shape in {k} mini batch for Y"
15 assert np.sum(np.sum(mini_batches[k][0] - mini_batches[k][0][0], axis=0)) == ((nx * (nx - 1) / 2 ) * mini_batch_size), "Wrong values. It happens if the order of X rows(features) changes"
AssertionError: Wrong shape in 0 mini batch for X
Here’s my implementation of that part:
# YOUR CODE STARTS HERE
s = m - mini_batch_size*num_complete_minibatches
mini_batch_X = shuffled_X[:, s]
mini_batch_Y = shuffled_Y[:, s]
# YOUR CODE ENDS HERE
What could be the issue?