Shortcuts

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 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, the out_dir will be the concatenation of out_dir and the last level directory of runner.work_dir. For example, if the input out_dir is ./tmp and runner.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 with out_suffix will be copied to out_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 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_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

before_run(runner)[source]

Infer self.file_client from self.out_dir. Initialize the self.start_iter and record the meta information.

Parameters:

runner (Runner) – The runner of the training process.

Return type:

None

Read the Docs v: latest
Versions
latest
stable
v0.10.3
v0.10.2
v0.10.1
v0.10.0
v0.9.1
v0.9.0
v0.8.5
v0.8.4
v0.8.3
v0.8.2
v0.8.1
v0.8.0
v0.7.4
v0.7.3
v0.7.2
v0.7.1
v0.7.0
v0.6.0
v0.5.0
v0.4.0
v0.3.0
v0.2.0
Downloads
epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.