LoggerHook¶
- 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
Runnerand write them to terminal, JSON file, tensorboard and wandb .etc.LoggerHookis used to record logs formatted byLogProcessorduring 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_dirwill be used by default. If specified, theout_dirwill be the concatenation ofout_dirand the last level directory ofrunner.work_dir. For example, if the inputout_diris./tmpandrunner.work_diris./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_dirending without_suffixwill be copied toout_dir. Defaults to (‘json’, ‘.log’, ‘.py’).keep_local (bool) – Whether to keep local logs in the local machine when
out_diris 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.FileClientfor details. Defaults to None. It will be deprecated in future. Please use backend_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 in runner.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)
- after_run(runner)[source]¶
Copy logs to
self.out_dirifself.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.
- after_test_iter(runner, batch_idx, data_batch=None, outputs=None)[source]¶
Record logs after testing iteration.
- after_train_iter(runner, batch_idx, data_batch=None, outputs=None)[source]¶
Record logs after training iteration.
- after_val_epoch(runner, metrics=None)[source]¶
All subclasses should override this method, if they need any operations after each validation epoch.