The batch_size in my code example would correspond to the batch size you set in your DataLoader.
To update the conf mat you would have to pass and return it from the method:
def confusion_matrix(preds, labels, conf_matrix):
    preds = torch.argmax(preds, 1)
    for p, t in zip(preds, labels):
        conf_matrix[p, t] += 1
    ...
    return conf_matrix

conf_matrix = torch.zeros(n_classes, n_classes)
for data, target in test_loader:
    output = ...
    conf_matrix = confusion_matrix(output, target, conf_matrix)




 Deb_Prakash_Chatterj:

Do I have to create another matrix for dataloader_test?


Yes, you shouldn’t mix the training, validation and test statistics.