Pytorch 中的模式设置:model.eval() 和 model.train()
model.train()
tells your model that you are training the model. So effectively layers like dropout, batchnorm etc. which behave different on the train and test procedures know what is going on and hence can behave accordingly.
More details: It sets the mode to train (see source code). You can call either model.eval()
or model.train(mode=False)
to tell that you are testing. It is somewhat intuitive to expect train
function to train model but it does not do that. It just sets the mode.
这两个函数并没有真正使网络运行起来,只是设置了网络的运行模式(是训练还是推理)
如果这篇文章帮助到了你,你可以请作者喝一杯咖啡
![](https://img2020.cnblogs.com/blog/938105/202010/938105-20201013171833350-276632012.png)