rai_toolbox.evaluating#
- class rai_toolbox.evaluating(*modules)[source]#
A context manager / decorator that temporarily places one or more modules in eval mode during the context.
- __init__(*modules)[source]#
- Parameters:
- *modules: tr.nn.Module
Notes
A module’s state is restored faithfully; e.g., a module that was already in eval mode will not be placed in train mode upon leaving the
evaluating
context.Examples
>>> from torch.nn import Linear >>> from rai_toolbox import evaluating
Using
evaluating
as a context manager.>>> module = Linear(1, 1) >>> module.training True >>> with evaluating(module): ... print(module.training) False >>> module.training True
Using
evaluating
as a decorator.>>> def f(): ... print("hello world") ... return module.training >>> f = evaluating(module)(f) >>> module.training True >>> f() hello world False >>> module.training True
Methods
__init__
(*modules)- Parameters: