CheckpointHook — mmengine 0.10.7 documentation (original) (raw)

class mmengine.hooks.CheckpointHook(interval=-1, by_epoch=True, save_optimizer=True, save_param_scheduler=True, out_dir=None, max_keep_ckpts=-1, save_last=True, save_best=None, rule=None, greater_keys=None, less_keys=None, file_client_args=None, filename_tmpl=None, backend_args=None, published_keys=None, save_begin=0, **kwargs)[source]

Save checkpoints periodically.

Parameters:

Examples

Save best based on single metric

CheckpointHook(interval=2, by_epoch=True, save_best='acc', rule='less')

Save best based on multi metrics with the same comparison rule

CheckpointHook(interval=2, by_epoch=True, save_best=['acc', 'mIoU'], rule='greater')

Save best based on multi metrics with different comparison rule

CheckpointHook(interval=2, by_epoch=True, save_best=['FID', 'IS'], rule=['less', 'greater'])

Save best based on single metric and publish model after training

CheckpointHook(interval=2, by_epoch=True, save_best='acc', rule='less', published_keys=['meta', 'state_dict'])

after_train(runner)[source]

Publish the checkpoint after training.

Parameters:

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

Return type:

None

after_train_epoch(runner)[source]

Save the checkpoint and synchronize buffers after each epoch.

Parameters:

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

Return type:

None

after_train_iter(runner, batch_idx, data_batch=None, outputs=typing.Optional[dict])[source]

Save the checkpoint and synchronize buffers after each iteration.

Parameters:

Return type:

None

after_val_epoch(runner, metrics)[source]

Save the checkpoint and synchronize buffers after each evaluation epoch.

Parameters:

before_train(runner)[source]

Finish all operations, related to checkpoint.

This function will get the appropriate file client, and the directory to save these checkpoints of the model.

Parameters:

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

Return type:

None