DLS Course 2: Improving Deep Neural Networks: Hyperparameter tuning, Regularization, and Optimization_Exercise 2 - random_mini_batches_2

i am getting below the error

please help me to resolve this issue


1 Like

Please see this information

Num training examples = 148
Mini batch size = 64

Since mini batch size is 64, we have to generate 3 mini batches:

  1. 2 mini batches of 64 training examples
  2. 1 (last ) mini batch of 148 - 64 * 2 = 148 - 128 = 20 training examples.

In your case, there are 84 training examples in the last mini batch and hence the assertion error.

Posting code in a public topic is discouraged and can get your account suspended. It’s okay to share stacktrace on a public post and send code to a mentor via direct message. Don’t forget to clean up the post. Here’s the community user guide to get started.

1 Like

Your logic using k, the loop index in the for loop, to compute the starting index for the last partial minibatch is incorrect.

To see why, try running the following code and watch what happens:

for ii in range(5):
    print(f"ii = {ii}")

print(f"After loop ii = {ii}")

Here’s the output:

ii = 0
ii = 1
ii = 2
ii = 3
ii = 4
After loop ii = 4
1 Like

Solved…got solution…

Thank you very much sir ,you made me to think and analyse the issue

1 Like