HookList¶
-
class
tfsnippet.HookList¶ Bases:
objectClass for managing hooks in
BaseTrainerandEvaluator.A hook is a registered callback that the trainers will call at certain time, during the training process. Apart from the callback method, each hook has a freq and a priority.
- The freq controls how often the particular hook should be called, e.g., every 2 epochs.
- The priority determines the priority (order) of calling the hooks. Smaller number corresponds to higher priority.
Methods Summary
add_hook(callback[, freq, priority])Add a hook into the list. call_hooks()Call all the registered hooks. remove(callback)Remove all hooks having the specified callback. remove_all()Remove all hooks. remove_by_priority(priority)Remove all hooks having the specified priority. remove_if(condition)Remove all hooks matching the specified condition. reset()Reset the frequency counter of all hooks. Methods Documentation
-
add_hook(callback, freq=1, priority=1000)¶ Add a hook into the list.
Parameters:
-
call_hooks()¶ Call all the registered hooks.
If any of the hook raises an error, it will stop the calling chain, and propagate the error to upper caller.
-
remove(callback)¶ Remove all hooks having the specified callback.
Parameters: callback – The callback of the hooks to be removed. Returns: The number of removed hooks. Return type: int
-
remove_by_priority(priority)¶ Remove all hooks having the specified priority.
Parameters: priority (int) – The priority of the hooks to be removed. Returns: The number of removed hooks. Return type: int
-
remove_if(condition)¶ Remove all hooks matching the specified condition.
Parameters: condition ((callback, freq, priority) -> bool) – A callable object to tell whether or not a hook should be removed. Returns: The number of removed hooks. Return type: int
-
reset()¶ Reset the frequency counter of all hooks.