# PyTorch CNN gives different results

**URL:** <https://discuss.pytorch.org/t/pytorch-cnn-gives-different-results/84766>\
**Category:** vision\
**Created:** [June 9, 2020, 1:18pm UTC](https://discuss.pytorch.org/t/pytorch-cnn-gives-different-results/84766 "2020-06-09T13:18:26Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![Nikronic](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/nikronic/32/71873_2.png) [@Nikronic](https://discuss.pytorch.org/u/Nikronic)\
**Post date:** [June 10, 2020, 11:28am UTC](https://discuss.pytorch.org/t/pytorch-cnn-gives-different-results/84766/4 "2020-06-10T11:28:42Z")

</div>

So, what I understand is that if you pass input `x` to model in case of `model.train()` everything is ok but for the same input `x`, `model.eval()` is giving worse result. `model.eval()` only affect layers such as batchnorm and dropout, so I guess you have such layers in your model definition. I think this post in that case can help alot as this is a tricky challenge sometimes:

> [@Model.eval() gives incorrect loss for model with batchnorm layers](https://discuss.pytorch.org/t/model-eval-gives-incorrect-loss-for-model-with-batchnorm-layers/7561/2):
>
> The testing code which is called every 100 training iters is as following: def test\_model(model): psnr\_test\_avg = 0 loss\_test\_avg = 0 model.eval() for iteration, test\_data in enumerate(dataloader\_test, 0): label\_test = test\_data['label\_patch'] residue\_test = test\_data['residue\_patch'] stacked\_test = test\_data['stacked\_patch'] microshift\_test = test\_data['train\_patch'] inputs\_test, residues\_test, labels\_test, microshifts\_test = Variabl…

There are few tricks to solve issue in the aforementioned thread. I hope it helps.

Bests

---

_[View the full topic](https://discuss.pytorch.org/t/pytorch-cnn-gives-different-results/84766)._
