Utilizing the hook system
A hook system allows incorporating classes to execute several tasks on training events. A custom hook builds upon inheriting a base class from Detectron2 called detectron2.engine.HookBase
. A hook allows the developer to execute tasks on four events by overriding the following methods:
before_training()
to include tasks to be executed before the first training iterationafter_training()
to include tasks to be executed after training completesbefore_step()
to include tasks to be executed before each training iterationafter_step()
to include tasks to be executed after each training iteration
The following code snippet creates a hook to read the evaluation metrics generated by COCOEvaluator
from the previously built custom trainer, keeps track of the best model with the highest [email protected] value, and saves the model as model_best.pth
:
# Some import statements are removed for space efficiency class BestModelHook(HookBase): ...