- 一直對於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