Solved by AnBucquet in post #2 
              
              
                Hi @Rosa, 
I think you can do it in your training function. This snippet should work: 
confusion_matrix = torch.zeros(nb_labels, nb_labels)
for inputs, labels in dataloaders[phase]:
       inputs = inputs.to(device)
       labels = labels.to(device)
       optimizer.zero_grad()

       with torch.se…