# Different test accuracy

**URL:** <https://discuss.pytorch.org/t/different-test-accuracy/68386>\
**Category:** Uncategorized\
**Created:** [February 2, 2020, 4:51am UTC](https://discuss.pytorch.org/t/different-test-accuracy/68386 "2020-02-02T04:51:06Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![oasjd7](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/oasjd7/32/5053_2.png) [@oasjd7](https://discuss.pytorch.org/u/oasjd7)\
**Post date:** [February 2, 2020, 4:51am UTC](https://discuss.pytorch.org/t/different-test-accuracy/68386/1 "2020-02-02T04:51:06Z")

</div>

1. In train phase, I got 99.41% accuracy on test loader and saved this model.
2. 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?

```auto
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

```
