I am trying to make a confusion matrix for my model, but it is not coming outright. There are 3 classes but my matrix is displaying 2x2 instead of 3x3.  Another issue I am having is that the numbers in my matrix do not equal the total number of images in my test set. Can someone help em figure out my error?

Run the testing batches
with torch.no_grad():
    for b, (pics, names) in enumerate(test_loader):
        
        if torch.cuda.is_available():
            pics = pics.cuda()
            names = names.cuda()
            
        b+=1

        # Apply the model
        y_val = MobileNet(pics)
        val_loss = criterion(y_val, names)
        # Tally the number of correct predictions
        test_predicted = torch.max(y_val.data, 1)[1] 
        tst_corr += (test_predicted == names).sum()
        
        test_correct.append(tst_corr)
        Val_accuracy = tst_corr.item()*100/(b*batch)
        # Print Validation results
        if b%7 == 0:
            print(f'test_epoch: {i:2}  batch: {b:4}  Val_loss: {val_loss.item():10.8f}  \Val_accuracy: {Val_accuracy:7.3f}%')
            test_acc.append(Val_accuracy)
            test_losses.append(val_loss)
            print("\n")

names = names.cpu()
test_predicted = test_predicted.cpu()
arr = confusion_matrix(names.view(-1), test_predicted.view(-1))
#df_cm = pd.DataFrame(arr, class_names, class_names)
plt.figure(figsize = (9,6))
sn.heatmap(df_cm, annot=True, fmt=“d”, cmap=‘BuGn’)
plt.xlabel(“prediction”)
plt.ylabel(“label (ground truth)”)
plt.show();