Hook¶
- class mmengine.hooks.Hook[source]¶
Base hook class.
All hooks should inherit from this class.
- after_load_checkpoint(runner, checkpoint)[source]¶
All subclasses should override this method, if they need any operations after loading the checkpoint.
- after_run(runner)[source]¶
All subclasses should override this method, if they need any operations before the training validation or testing process.
- Parameters:
runner (Runner) – The runner of the training, validation or testing process.
- Return type:
None
- after_test(runner)[source]¶
All subclasses should override this method, if they need any operations after testing.
- Parameters:
runner (Runner) – The runner of the testing process.
- Return type:
None
- after_test_epoch(runner, metrics=None)[source]¶
All subclasses should override this method, if they need any operations after each test epoch.
- after_test_iter(runner, batch_idx, data_batch=None, outputs=None)[source]¶
All subclasses should override this method, if they need any operations after each test iteration.
- after_train(runner)[source]¶
All subclasses should override this method, if they need any operations after train.
- Parameters:
runner (Runner) – The runner of the training process.
- Return type:
None
- after_train_epoch(runner)[source]¶
All subclasses should override this method, if they need any operations after each training epoch.
- Parameters:
runner (Runner) – The runner of the training process.
- Return type:
None
- after_train_iter(runner, batch_idx, data_batch=None, outputs=None)[source]¶
All subclasses should override this method, if they need any operations after each training iteration.
- after_val(runner)[source]¶
All subclasses should override this method, if they need any operations after validation.
- Parameters:
runner (Runner) – The runner of the validation process.
- Return type:
None
- after_val_epoch(runner, metrics=None)[source]¶
All subclasses should override this method, if they need any operations after each validation epoch.
- after_val_iter(runner, batch_idx, data_batch=None, outputs=None)[source]¶
All subclasses should override this method, if they need any operations after each validation iteration.
- before_run(runner)[source]¶
All subclasses should override this method, if they need any operations before the training validation or testing process.
- Parameters:
runner (Runner) – The runner of the training, validation or testing process.
- Return type:
None
- before_save_checkpoint(runner, checkpoint)[source]¶
All subclasses should override this method, if they need any operations before saving the checkpoint.
- before_test(runner)[source]¶
All subclasses should override this method, if they need any operations before testing.
- Parameters:
runner (Runner) – The runner of the testing process.
- Return type:
None
- before_test_epoch(runner)[source]¶
All subclasses should override this method, if they need any operations before each test epoch.
- Parameters:
runner (Runner) – The runner of the testing process.
- Return type:
None
- before_test_iter(runner, batch_idx, data_batch=None)[source]¶
All subclasses should override this method, if they need any operations before each test iteration.
- before_train(runner)[source]¶
All subclasses should override this method, if they need any operations before train.
- Parameters:
runner (Runner) – The runner of the training process.
- Return type:
None
- before_train_epoch(runner)[source]¶
All subclasses should override this method, if they need any operations before each training epoch.
- Parameters:
runner (Runner) – The runner of the training process.
- Return type:
None
- before_train_iter(runner, batch_idx, data_batch=None)[source]¶
All subclasses should override this method, if they need any operations before each training iteration.
- before_val(runner)[source]¶
All subclasses should override this method, if they need any operations before validation.
- Parameters:
runner (Runner) – The runner of the validation process.
- Return type:
None
- before_val_epoch(runner)[source]¶
All subclasses should override this method, if they need any operations before each validation epoch.
- Parameters:
runner (Runner) – The runner of the validation process.
- Return type:
None
- before_val_iter(runner, batch_idx, data_batch=None)[source]¶
All subclasses should override this method, if they need any operations before each validation iteration.
- end_of_epoch(dataloader, batch_idx)[source]¶
Check whether the current iteration reaches the last iteration of the dataloader.
- every_n_epochs(runner, n, start=0)[source]¶
Test whether current epoch can be evenly divided by n.
- Parameters:
- Returns:
Whether current epoch can be evenly divided by n.
- Return type:
- every_n_inner_iters(batch_idx, n)[source]¶
Test whether current inner iteration can be evenly divided by n.
- every_n_train_iters(runner, n, start=0)[source]¶
Test whether current training iteration can be evenly divided by n.
- Parameters:
- Returns:
Return True if the current iteration can be evenly divided by n, otherwise False.
- Return type:
- get_triggered_stages()[source]¶
Get all triggered stages with method name of the hook.
- Returns:
List of triggered stages.
- Return type: