Shortcuts

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.

Parameters
  • runner (Runner) – The runner of the training, validation or testing process.

  • checkpoint (dict) – Model’s checkpoint.

Return type

None

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.

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]

All subclasses should override this method, if they need any operations after each test iteration.

Parameters
  • runner (Runner) – The runner of the training 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(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.

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(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.

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]

All subclasses should override this method, if they need any operations after each validation iteration.

Parameters
  • runner (Runner) – The runner of the validation process.

  • batch_idx (int) – The index of the current batch in the val loop.

  • data_batch (dict or tuple or list, optional) – Data from dataloader.

  • outputs (Sequence, optional) – Outputs from model.

Return type

None

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.

Parameters
  • runner (Runner) – The runner of the training, validation or testing process.

  • checkpoint (dict) – Model’s checkpoint.

Return type

None

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.

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. Defaults to None.

Return type

None

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.

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 or tuple or list, optional) – Data from dataloader.

Return type

None

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.

Parameters
  • runner (Runner) – The runner of the validation process.

  • batch_idx (int) – The index of the current batch in the val loop.

  • data_batch (dict, optional) – Data from dataloader. Defaults to None.

Return type

None

end_of_epoch(dataloader, batch_idx)[source]

Check whether the current iteration reaches the last iteration of the dataloader.

Parameters
  • dataloader (Dataloader) – The dataloader of the training, validation or testing process.

  • batch_idx (int) – The index of the current batch in the loop.

Returns

Whether reaches the end of current epoch or not.

Return type

bool

every_n_epochs(runner, n)[source]

Test whether current epoch can be evenly divided by n.

Parameters
  • runner (Runner) – The runner of the training, validation or testing process.

  • n (int) – Whether current epoch can be evenly divided by n.

Returns

Whether current epoch can be evenly divided by n.

Return type

bool

every_n_inner_iters(batch_idx, n)[source]

Test whether current inner iteration can be evenly divided by n.

Parameters
  • batch_idx (int) – Current batch index of the training, validation or testing loop.

  • n (int) – Whether current inner iteration can be evenly divided by n.

Returns

Whether current inner iteration can be evenly divided by n.

Return type

bool

every_n_train_iters(runner, n)[source]

Test whether current training iteration can be evenly divided by n.

Parameters
  • runner (Runner) – The runner of the training, validation or testing process.

  • n (int) – Whether current iteration can be evenly divided by n.

Returns

Return True if the current iteration can be evenly divided by n, otherwise False.

Return type

bool

get_triggered_stages()[source]

Get all triggered stages with method name of the hook.

Returns

List of triggered stages.

Return type

list

is_last_train_epoch(runner)[source]

Test whether current epoch is the last train epoch.

Parameters

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

Returns

Whether reaches the end of training epoch.

Return type

bool

is_last_train_iter(runner)[source]

Test whether current iteration is the last train iteration.

Parameters

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

Returns

Whether current iteration is the last train iteration.

Return type

bool

Read the Docs v: v0.6.0
Versions
latest
stable
v0.6.0
v0.5.0
v0.4.0
v0.3.0
v0.2.0
Downloads
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.