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

hs99: <p>I have the code to evaluate the model <img src="https://discuss.pytorch.org/images/emoji/apple/slight_smile.png?v=12" title=":slight_smile:" class="emoji" alt=":slight_smile:" loading="lazy" width="20" height="20"></p>
<p>def evaluate_model(model, test_loader, criterion, best_model_name):<br>
model.load_state_dict(torch.load(best_model_name))</p>
<pre><code># Specify the heartbeat classes from above
classes = {
    0: 'N - Normal Beat', 
    1: 'S - Supraventricular premature or ectopic beat',
    2: 'V - Premature ventricular contraction', 
    3: 'F - Fusion of ventricular and normal beat', 
    4: 'Q - Unclassified beat'}

# track test loss
test_loss = 0.0
class_correct = list(0. for i in range(5))
class_total = list(0. for i in range(5))

model.eval()
# iterate over test data
for data, target in test_loader:
    # move tensors to GPU if CUDA is available
    if train_on_gpu:
        data, target = data.cuda(), target.cuda()
    # forward pass: compute predicted outputs by passing inputs to the model
    #print(data.float())
    output = model(data.float())
    # calculate the batch loss
    loss = criterion(output, target.long())
    # update test loss 
    test_loss += loss.item()*data.size(0)
    # convert output probabilities to predicted class
    _, pred = torch.max(output, 1)
    # compare predictions to true label
    correct_tensor = pred.eq(target.data.view_as(pred))
    correct = np.squeeze(correct_tensor.numpy()) if not train_on_gpu else np.squeeze(correct_tensor.cpu().numpy())
    # calculate test accuracy for each object class
    for i in range(batch_size):
        label = target.data[i].int()
        class_correct[label] += correct[i].item()
        class_total[label] += 1

# average test loss
test_loss = test_loss/len(test_loader.dataset)
print('Test Loss: {:.6f}\n'.format(test_loss))

for i in range(5):
    if class_total[i] &gt; 0:
        print('Test Accuracy of %5s: %2d%% (%2d/%2d)' % (
            classes[i], 100 * class_correct[i] / class_total[i],
            np.sum(class_correct[i]), np.sum(class_total[i])))
    else:
        print('Test Accuracy of %5s: N/A (no training examples)' % (classes[i]))

print('\nTest Accuracy (Overall): %2d%% (%2d/%2d)' % (
    100. * np.sum(class_correct) / np.sum(class_total),
    np.sum(class_correct), np.sum(class_total)))
</code></pre>
<hr>
<p>When I run <img src="https://discuss.pytorch.org/images/emoji/apple/slight_smile.png?v=12" title=":slight_smile:" class="emoji" alt=":slight_smile:" loading="lazy" width="20" height="20"></p>
<p>evaluate_model(model_1, test_loader_1, criterion, ‘model_ecg_heartbeat_categorization_1.pt’)</p>
<p>I get the output as:<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/c/c/cc43fa016588a91ae1ed95edcb4df31c8a647c87.png" data-download-href="https://discuss.pytorch.org/uploads/default/cc43fa016588a91ae1ed95edcb4df31c8a647c87" title="image"><img src="https://discuss.pytorch.org/uploads/default/original/3X/c/c/cc43fa016588a91ae1ed95edcb4df31c8a647c87.png" alt="image" data-base62-sha1="t912FNgjv13ZijtziWY9EEMQ6PR" width="690" height="206" data-dominant-color="292D34"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">image</span><span class="informations">793×237 28.5 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<p>criterion is NLLLoss and batch size is 32</p>
<p>How do I correct it ??Pls help !!</p>