pyanomaly.core.hook.abstract package¶
Submodules¶
pyanomaly.core.hook.abstract.abstract_hook module¶
@author: Yuhao Cheng @contact: yuhao.cheng[at]outlook.com
-
class
pyanomaly.core.hook.abstract.abstract_hook.EvaluateHook¶ Bases:
pyanomaly.core.hook.abstract.abstract_hook.HookBase-
after_step(current_step)¶ Called after each iteration.
-
abstract
evaluate(current_step) → float¶
-
inference()¶
-
-
class
pyanomaly.core.hook.abstract.abstract_hook.HookBase¶ Bases:
objectBase class for hooks that can be registered with
TrainerBase. Each hook can implement 4 methods. The way they are called is demonstrated in the following snippet: .. code-block:: pythonhook.before_train() for iter in range(start_iter, max_iter):
hook.before_step() trainer.run_step() hook.after_step()
hook.after_train()
- Notes:
In the hook method, users can access self.trainer to access more properties about the context (e.g., current iteration).
A hook that does something in
before_step()can often be implemented equivalently inafter_step(). If the hook takes non-trivial time, it is strongly recommended to implement the hook inafter_step()instead ofbefore_step(). The convention is thatbefore_step()should only take negligible time. Following this convention will allow hooks that do care about the difference betweenbefore_step()andafter_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.
-
after_step(current_step)¶ Called after each iteration.
-
after_train()¶ Called after the last iteration.
-
before_step(current_step)¶ Called before each iteration.
-
before_train()¶ Called before the first iteration.
Module contents¶
@author: Yuhao Cheng @contact: yuhao.cheng[at]outlook.com