PyTorch CNN gives different results

chandra_sutrisno: <p>I am trying to make a face recognition model with PyTorch. My model performs well with both loss scores for training and validation close to 0. The problem is when I tested it using same input, it gives me different results like below:</p>
<p><img src="https://discuss.pytorch.org/uploads/default/original/3X/e/b/ebec5c08efc8ba34c79d08a1a7bd5763d9a33621.png" alt="output2" data-base62-sha1="xF4BpKxSoecNEzlV7kr0ee5heyB" width="189" height="145"></p>
<p>and below</p>
<p><img src="https://discuss.pytorch.org/uploads/default/original/3X/4/b/4b3870ad72b4ea6c5b36951d26febbff4ca036f5.png" alt="output1" data-base62-sha1="aJqJqEtSre295yQs06FpHJHW4GV" width="171" height="153"></p>
<p>The left side is the true label and the right one is the prediction output. I set random seed and ran</p>
<blockquote>
<p>model.eval()</p>
</blockquote>
<p>before feeding the input to the model.</p>
<p>Does anyone know how to solve this?</p>
<p>Please advise</p>

Nikronic: <p>Hi,</p>
<p>What is the problem? It seems it just doing fine. Could you explain what is your expectation and what is the difference of these values from your expectations?<br>
As I see, it has only one error which is normal as you testing the model and not training and in any model that has not overfitted, test loss/ test accuracy is higher/lower than train mode.</p>
<p>Bests</p>

chandra_sutrisno: <p>Hi <a class="mention" href="/u/nikronic">@Nikronic</a>,</p>
<p>I missed some words, sorry for that. I meant i tested it using the same input and it gave me different results.</p>

Nikronic: <p>So, what I understand is that if you pass input <code>x</code> to model in case of <code>model.train()</code> everything is ok but for the same input <code>x</code>, <code>model.eval()</code> is giving worse result. <code>model.eval()</code> 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:</p><aside class="quote quote-modified" data-post="2" data-topic="7561">
  <div class="title">
    <div class="quote-controls"></div>
    <img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/zhangboknight/48/15722_2.png" class="avatar">
    <a href="https://discuss.pytorch.org/t/model-eval-gives-incorrect-loss-for-model-with-batchnorm-layers/7561/2">Model.eval() gives incorrect loss for model with batchnorm layers</a> 
  </div>
  <blockquote>
    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…
  </blockquote>
</aside>

<p>There are few tricks to solve issue in the aforementioned thread. I hope it helps.</p>
<p>Bests</p>

chandra_sutrisno: <p>Hi <a class="mention" href="/u/nikronic">@Nikronic</a></p>
<p>Thank you. I will check later.</p>

Dicko: <p>I am hoping somebody can help me because I am banging by head against a brick wall <img src="https://discuss.pytorch.org/images/emoji/apple/stuck_out_tongue.png?v=9" title=":stuck_out_tongue:" class="emoji" alt=":stuck_out_tongue:"><br>
I am using the RetinaNet notebook (link posted in my post above), after running different experiments my results were getting worse and no where near what I got the first time round so I decided to do a check.<br>
I looked at the model where I got good reults, an mAP of 0.36<br>
So I took tha same model, same notebook, same data, changed NOTHING and my results are terrible mAP 0.15. Has anyone come across this before ? I haven’t changed a thing but I know that something must be different and I can’t seem to find out what it is!.<br>
Thanks</p>