PyTorch中,关于model.eval()和torch.no_grad()


  • 一直对于model.eval()和torch.no_grad()有些疑惑
  • 之前看博客说,只用torch.no_grad()即可
  • 但是今天查资料,发现不是这样,而是两者都用,因为两者有着不同的作用
  • 引用stackoverflow:

Use both. They do different things, and have different scopes.
with torch.no_grad: disables tracking of gradients in autograd.
model.eval(): changes the forward() behaviour of the module it is called upon. eg, it disables dropout and has batch norm use the entire population statistics


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM