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: object

Base 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:: 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 before_step() can often be implemented equivalently in after_step(). If the hook takes non-trivial time, it is strongly recommended to implement the hook in after_step() instead of before_step(). The convention is that before_step() should only take negligible time. Following this convention will allow hooks that do care about the difference between before_step() and 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.

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