查看: 1455|回复: 0

torch.no_grad()与model.eval()

[复制链接]

665

主题

1234

帖子

6567

积分

xdtech

Rank: 5Rank: 5

积分
6567
发表于 2020-4-27 08:59:57 | 显示全部楼层 |阅读模式
  • 一直对于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

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表