pythonmachine-learningdeep-learningpytorchmode

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?


Solution

  • From the Pytorch forum, with a small tweak:

    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