# Model.eval() accuracy is 0 and running\_corrects is 0

**URL:** <https://discuss.pytorch.org/t/model-eval-accuracy-is-0-and-running-corrects-is-0/123271>\
**Category:** audio\
**Created:** [June 4, 2021, 9:54am UTC](https://discuss.pytorch.org/t/model-eval-accuracy-is-0-and-running-corrects-is-0/123271 "2021-06-04T09:54:36Z")\
**Posts on this page:** 1\
**Showing post:** 13

<div class="post-metadata">

**Author:** ![ptrblck](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/ptrblck/32/1823_2.png) [@ptrblck](https://discuss.pytorch.org/u/ptrblck)\
**Post date:** [June 6, 2021, 11:12pm UTC](https://discuss.pytorch.org/t/model-eval-accuracy-is-0-and-running-corrects-is-0/123271/13 "2021-06-06T23:12:59Z")

</div>

> [@Henry\_Chibueze](#):
>
> The training and weight updates only happened in the train function, so if u call the model any other place, it won’t have those trained weights and It’ll still be the untrained model it is…simply because you passed the model as a parameter to the train function and made the trained model peculiar to just the train function.

I don’t think that’s correct as seen e.g. here:

```python
import torch
import torch.nn as nn

def train(model, optimizer):
    for epoch in range(10):
        optimizer.zero_grad()
        output = model(torch.randn(1, 1))
        loss = criterion(output, torch.randn(1, 1))
        loss.backward()
        optimizer.step()
        print('epoch {}, loss {}, weight {}'.format(
            epoch, loss.item(), model.weight))

if __name__ ==' __main__':
    model = nn.Linear(1, 1)
    print('before training')
    print(model.weight)
    
    optimizer = torch.optim.SGD(model.parameters(), lr=1.)
    criterion = nn.MSELoss()
    
    train(model, optimizer)
    print('after training')
    print(model.weight)

```

As you can see, the model is created in the if-clause guard, passed to the train function, and is not returned.  
Nevertheless, the weight updates will be performed inplace on the model reference and thus the model in the same scope will contain the upgraded parameters.

---

_[View the full topic](https://discuss.pytorch.org/t/model-eval-accuracy-is-0-and-running-corrects-is-0/123271)._
