- In train phase, I got 99.41% accuracy on test loader and saved this model.
- After train process, I load above model and test -> accuracy: 99.26%
For both train and test phase, I use this test() code.
In test phase, When I remove model.eval()
I can get 99.41%.
How can I understand this situation?
In train phase, model.eval()
is also applied…then why test_accuracy is different?
def test(model, dataloader):
model.eval()
s_correct = 0
s_total = 0
for batch_idx, (img, label) in enumerate(dataloader):
img, label = img.cuda(), label.cuda()
with torch.no_grad():
outputs = model(img)
_, predicted = outputs.max(1)
s_total += label.size(0)
s_correct += predicted.eq(label).sum().item()
model.train()
acc = s_correct / s_total
return acc