Safemotion Lib
Loading...
Searching...
No Matches
Public Member Functions | List of all members
fastreid.engine.train_loop.HookBase Class Reference
Inheritance diagram for fastreid.engine.train_loop.HookBase:
fastreid.engine.hooks.AutogradProfiler fastreid.engine.hooks.CallbackHook fastreid.engine.hooks.EvalHook fastreid.engine.hooks.FreezeLayer fastreid.engine.hooks.IterationTimer fastreid.engine.hooks.LRScheduler fastreid.engine.hooks.PeriodicCheckpointer fastreid.engine.hooks.PeriodicWriter fastreid.engine.hooks.PreciseBN fastreid.engine.hooks.SWA

Public Member Functions

 before_train (self)
 
 after_train (self)
 
 before_step (self)
 
 after_step (self)
 

Detailed Description

Base class for hooks that can be registered with :class:`TrainerBase`.
Each hook can implement 4 methods. The way they are called is demonstrated
in the following snippet:
.. code-block:: python
    hook.before_train()
    for iter in range(start_iter, max_iter):
        hook.before_step()
        trainer.run_step()
        hook.after_step()
    hook.after_train()
Notes:
    1. In the hook method, users can access `self.trainer` to access more
       properties about the context (e.g., current iteration).
    2. A hook that does something in :meth:`before_step` can often be
       implemented equivalently in :meth:`after_step`.
       If the hook takes non-trivial time, it is strongly recommended to
       implement the hook in :meth:`after_step` instead of :meth:`before_step`.
       The convention is that :meth:`before_step` should only take negligible time.
       Following this convention will allow hooks that do care about the difference
       between :meth:`before_step` and :meth:`after_step` (e.g., timer) to
       function properly.
Attributes:
    trainer: A weak reference to the trainer object. Set by the trainer when the hook is
        registered.

Definition at line 22 of file train_loop.py.

Member Function Documentation

◆ after_step()

fastreid.engine.train_loop.HookBase.after_step ( self)

◆ after_train()

fastreid.engine.train_loop.HookBase.after_train ( self)
Called after the last iteration.

Reimplemented in fastreid.engine.hooks.CallbackHook, fastreid.engine.hooks.IterationTimer, fastreid.engine.hooks.PeriodicWriter, and fastreid.engine.hooks.EvalHook.

Definition at line 56 of file train_loop.py.

56 def after_train(self):
57 """
58 Called after the last iteration.
59 """
60 pass
61

◆ before_step()

fastreid.engine.train_loop.HookBase.before_step ( self)
Called before each iteration.

Reimplemented in fastreid.engine.hooks.CallbackHook, fastreid.engine.hooks.IterationTimer, fastreid.engine.hooks.AutogradProfiler, fastreid.engine.hooks.FreezeLayer, and fastreid.engine.hooks.SWA.

Definition at line 62 of file train_loop.py.

62 def before_step(self):
63 """
64 Called before each iteration.
65 """
66 pass
67

◆ before_train()

fastreid.engine.train_loop.HookBase.before_train ( self)
Called before the first iteration.

Reimplemented in fastreid.engine.hooks.CallbackHook, fastreid.engine.hooks.IterationTimer, and fastreid.engine.hooks.PeriodicCheckpointer.

Definition at line 50 of file train_loop.py.

50 def before_train(self):
51 """
52 Called before the first iteration.
53 """
54 pass
55

The documentation for this class was generated from the following file: