Loading a model, getting different results

DJ_1992: <p>I saved and loaded a model using</p>
<pre><code class="lang-auto">torch.save({'state_dict': model.state_dict()}, "classifier.pth")

state_dict = torch.load('classifier.pth')
model.load_state_dict(state_dict["state_dict"])

</code></pre>
<p>I was getting 93% accuracy in a classification on the validation set which got reduced to 76% after I restarted the kernel… Am I making some mistake…Please help</p>

anilg: <p>That shouldn’t be. Are you sure that you are feeding the same dataset?</p>

DJ_1992: <p>Yes I didnt change anything , just restarted the kernel…<br>
I am adding some screenshots of new results…<br>
Here I loaded the model<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/e/6/e611c3ac49db2cd002e8cc05290dbb1e7b66181b.png" data-download-href="https://discuss.pytorch.org/uploads/default/e611c3ac49db2cd002e8cc05290dbb1e7b66181b" title="Screenshot at Apr 23 12-54-00"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/e/6/e611c3ac49db2cd002e8cc05290dbb1e7b66181b_2_690x351.png" alt="Screenshot at Apr 23 12-54-00" data-base62-sha1="wPhSrzYqIygTtAEz8UDOWYQhuc3" width="690" height="351" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/e/6/e611c3ac49db2cd002e8cc05290dbb1e7b66181b_2_690x351.png, https://discuss.pytorch.org/uploads/default/original/3X/e/6/e611c3ac49db2cd002e8cc05290dbb1e7b66181b.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/e/6/e611c3ac49db2cd002e8cc05290dbb1e7b66181b.png 2x" data-dominant-color="ECEAEA"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">Screenshot at Apr 23 12-54-00</span><span class="informations">718×366 40.8 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div><br>
Here I restarted the kernel and loaded the model<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/d/d/dde263e2f98f7038f5b433bd6c129812ddfbcb65.png" data-download-href="https://discuss.pytorch.org/uploads/default/dde263e2f98f7038f5b433bd6c129812ddfbcb65" title="Screenshot at Apr 23 12-58-07"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/d/d/dde263e2f98f7038f5b433bd6c129812ddfbcb65_2_690x348.png" alt="Screenshot at Apr 23 12-58-07" data-base62-sha1="vESyHtzqj4Mj2ZvMj88hBrRWUUl" width="690" height="348" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/d/d/dde263e2f98f7038f5b433bd6c129812ddfbcb65_2_690x348.png, https://discuss.pytorch.org/uploads/default/original/3X/d/d/dde263e2f98f7038f5b433bd6c129812ddfbcb65.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/d/d/dde263e2f98f7038f5b433bd6c129812ddfbcb65.png 2x" data-dominant-color="ECEAEB"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">Screenshot at Apr 23 12-58-07</span><span class="informations">728×368 44.1 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>

copperwiring: <p>I see it’s an old discussion but I’d recommend setting seed value</p>

DJ_1992: <p>I saved it this way, so was working fine</p>
<blockquote>
<p>torch.save(model, ‘filename.pt’)</p>
</blockquote>