IndexError: index 10 is out of bounds for dimension 0 with size 10

I’ve been stuck here for a while now. Any help.

1 Like

code: batch_size = 30

The last batch given by your DataLoader might be smaller, if the length of your Dataset is not divisible by the batch size without a remainder.
Try to get the current batch size inside the training loop:

for data, target in testloader:
    batch_size = data.size(0)
    for i in range(batch_size):

I worked perfectly!!! :grinning: Thank you!