简体   繁体   English

如何在 Pytorch 中检查 model 是否处于训练或评估模式?

[英]How to check if a model is in train or eval mode in Pytorch?

How to check from within a model if it is currently in train or eval mode?如何从 model 中检查它当前是否处于训练或评估模式?

From the Pytorch forum , with a small tweak:来自Pytorch 论坛,稍作调整:

use利用

if self.training:
    # it's in train mode
else:
    # it's in eval mode

Always better to have a stack overflow answer than to look at forums.获得堆栈溢出答案总是比查看论坛更好。

Explanation about the modes 模式说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM