LoggerHook — mmengine 0.10.7 documentation (original) (raw)
class mmengine.hooks.LoggerHook(interval=10, ignore_last=True, interval_exp_name=1000, out_dir=None, out_suffix=('.json', '.log', '.py', 'yaml'), keep_local=True, file_client_args=None, log_metric_by_epoch=True, backend_args=None)[source]¶
Collect logs from different components of Runner
and write them to terminal, JSON file, tensorboard and wandb .etc.
LoggerHook
is used to record logs formatted by LogProcessor
during training/validation/testing phase. It is used to control following behaviors:
- The frequency of logs update in terminal, local, tensorboad wandb.etc.
- The frequency of show experiment information in terminal.
- The work directory to save logs.
Parameters:
- interval (int) – Logging interval (every k iterations). Defaults to 10.
- ignore_last (bool) – Ignore the log of last iterations in each epoch if the number of remaining iterations is less than
interval
. Defaults to True. - interval_exp_name (int) – Logging interval for experiment name. This feature is to help users conveniently get the experiment information from screen or log file. Defaults to 1000.
- out_dir (str or Path , optional) – The root directory to save checkpoints. If not specified,
runner.work_dir
will be used by default. If specified, theout_dir
will be the concatenation ofout_dir
and the last level directory ofrunner.work_dir
. For example, if the inputout_dir
is./tmp
andrunner.work_dir
is./work_dir/cur_exp
, then the log will be saved in./tmp/cur_exp
. Defaults to None. - out_suffix (Tuple _[_str] or str) – Those files in
runner._log_dir
ending without_suffix
will be copied toout_dir
. Defaults to (‘json’, ‘.log’, ‘.py’). - keep_local (bool) – Whether to keep local logs in the local machine when
out_dir
is specified. If False, the local log will be removed. Defaults to True. - file_client_args (dict, optional) – Arguments to instantiate a FileClient. See mmengine.fileio.FileClient for details. Defaults to None. It will be deprecated in future. Please usebackend_args instead.
- log_metric_by_epoch (bool) – Whether to output metric in validation step by epoch. It can be true when running in epoch based runner. If set to True, after_val_epoch will set step to self.epoch inrunner.visualizer.add_scalars. Otherwise step will be self.iter. Defaults to True.
- backend_args (dict, optional) – Arguments to instantiate the prefix of uri corresponding backend. Defaults to None. New in v0.2.0.
Examples
The simplest LoggerHook config.
logger_hook_cfg = dict(interval=20)
Copy logs to self.out_dir
if self.out_dir is not None
Parameters:
runner (Runner) – The runner of the training/testing/validation 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.
Parameters:
- runner (Runner) – The runner of the testing process.
- metrics (Dict [_str,_ float] , optional) – Evaluation results of all metrics on test dataset. The keys are the names of the metrics, and the values are corresponding results.
Return type:
None
after_test_iter(runner, batch_idx, data_batch=None, outputs=None)[source]¶
Record logs after testing iteration.
Parameters:
- runner (Runner) – The runner of the testing process.
- batch_idx (int) – The index of the current batch in the test loop.
- data_batch (dict or tuple or list, optional) – Data from dataloader.
- outputs (sequence , optional) – Outputs from model.
Return type:
None
after_train_iter(runner, batch_idx, data_batch=None, outputs=None)[source]¶
Record logs after training iteration.
Parameters:
- runner (Runner) – The runner of the training process.
- batch_idx (int) – The index of the current batch in the train loop.
- data_batch (dict tuple or list, optional) – Data from dataloader.
- outputs (dict, optional) – Outputs from model.
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.
Parameters:
- runner (Runner) – The runner of the validation process.
- metrics (Dict [_str,_ float] , optional) – Evaluation results of all metrics on validation dataset. The keys are the names of the metrics, and the values are corresponding results.
Return type:
None
after_val_iter(runner, batch_idx, data_batch=None, outputs=None)[source]¶
Record logs after validation iteration.
Parameters:
- runner (Runner) – The runner of the validation process.
- batch_idx (int) – The index of the current batch in the validation loop.
- data_batch (dict or tuple or list, optional) – Data from dataloader. Defaults to None.
- outputs (sequence , optional) – Outputs from model.
Return type:
None
Infer self.file_client
from self.out_dir
. Initialize theself.start_iter
and record the meta information.
Parameters:
runner (Runner) – The runner of the training process.
Return type:
None