Hey @Syed_Hamza_Tehseen,
For building this logic, 4 variables will come in handy to you:
-
m
= Total number of samples, which you can use for defining the last mini-batch -
mini_batch_size
= Maximum number of samples in a mini-batch, which you can use to find the indices of the various mini-batches. -
num_complete_minibatches
= Denotes the total number of mini-batches, consisting of samples equal tomini_batch_size
-
k
= Denotes the indices for the mini-batches
Note that all of these variables have already been defined for you. Now, let’s say that k = 2
and mini_batch_size = 32
. Since k = 2
, this means we are referring to the 3rd mini-batch (since indexing begins from 0 in Python). Now in this case, the first mini-batch will have samples indexed from 0 to 31. Similarly, the second mini-batch will have samples indexed from 32 to 63.
Now, the 3rd mini-batch, which we are concerned about has samples indexed from 64 to 95. If we contemplate k * mini_batch_size = 64
and (k * mini_batch_size) - 1 = 95
. Voila, our indices Cherry on the cake, when you use slicing for indexing in Python, it doesn’t include the element corresponding to the closing index, i.e., if you use
X[start, end]
, this won’t include the sample X[end]
. Now, I leave it up to you to figure out the code for the last mini-batch.
Cheers,
Elemento