19

How to check from within a model if it is currently in train or eval mode?

Gulzar
  • 23,452
  • 27
  • 113
  • 201

1 Answers1

27

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

Gulzar
  • 23,452
  • 27
  • 113
  • 201