Also while plotting confusion matrix there’ s a problem i have only 1493 images in total and 1045 go for training and 448 for testing…but the confusion matrix rows sum up to 5100…what can be the error.

#preds = torch.tensor([])
confusion_matrix = torch.zeros(num_classes, num_classes)
def evaluation(dataloader, model):
model added as argument - 1 change from lenet
total, correct = 0,0
for data in dataloader:
inputs, labels, imgindex  = data
inputs, labels, imgindex = inputs.to(device), labels.to(device), imgindex
# inputs are put in the gpu
outputs = model(inputs)
# from net to model - 2 change from lenet
_, pred = torch.max(outputs.data,1)
for t, p in zip(labels.view(-1), pred.view(-1)):
confusion_matrix[t.long(), p.long()] +=1
total += labels.size(0)
correct +=(pred==labels).sum().item()
return 100 * correct/total

this is the evaluation function

Screenshot (1379)903×705 24.3 KB