Yes, I call model.eval() while computing test. Also I am not able to get the same values outside of this valid_loss condition just by repeatedly calling into the self.test method. When I turn off shuffle for dataloader I get same result.
Here is the computation of a,b,c,d →
def test(self,testloader):
test_score_f1 = 0
test_score_accuracy = 0
test_score_recall = 0
test_score_presicion = 0
self.eval()
for data, target in testloader:
with torch.no_grad():
output = self(data)
_,output = torch.max(output,1)
test_score_f1 = test_score_f1 + self.f1(output,target)
test_score_accuracy = test_score_accuracy + self.accuracy(output,target)
test_score_recall = test_score_recall + self.recall(output,target)
test_score_presicion = test_score_presicion + self.presicion(output,target)
test_score_f1 = data.shape[0]*test_score_f1/len(test_dataset)
test_score_accuracy = data.shape[0]*test_score_accuracy/len(test_dataset)
test_score_recall = data.shape[0]*test_score_recall/len(test_dataset)
test_score_presicion = data.shape[0]*test_score_presicion/len(test_dataset)
return test_score_f1,test_score_accuracy,test_score_recall,test_score_presicion