paddlespeech.s2t.utils.checkpoint module

class paddlespeech.s2t.utils.checkpoint.Checkpoint(kbest_n: int = 5, latest_n: int = 1)[source]

Bases: object

Methods

load_best_parameters(model[, optimizer, ...])

Load a last model checkpoint from disk. Args: model (Layer): model to load parameters. optimizer (Optimizer, optional): optimizer to load states if needed. Defaults to None. checkpoint_dir (str, optional): the directory where checkpoint is saved. checkpoint_path (str, optional): if specified, load the checkpoint stored in the checkpoint_path(prefix) and the argument 'checkpoint_dir' will be ignored. Defaults to None. Returns: configs (dict): epoch or step, lr and other meta info should be saved.

load_latest_parameters(model[, optimizer, ...])

Load a last model checkpoint from disk. Args: model (Layer): model to load parameters. optimizer (Optimizer, optional): optimizer to load states if needed. Defaults to None. checkpoint_dir (str, optional): the directory where checkpoint is saved. checkpoint_path (str, optional): if specified, load the checkpoint stored in the checkpoint_path(prefix) and the argument 'checkpoint_dir' will be ignored. Defaults to None. Returns: configs (dict): epoch or step, lr and other meta info should be saved.

load_parameters(model[, optimizer, ...])

Load a last model checkpoint from disk. Args: model (Layer): model to load parameters. optimizer (Optimizer, optional): optimizer to load states if needed. Defaults to None. checkpoint_dir (str, optional): the directory where checkpoint is saved. checkpoint_path (str, optional): if specified, load the checkpoint stored in the checkpoint_path(prefix) and the argument 'checkpoint_dir' will be ignored. Defaults to None. record_file "checkpoint_latest" or "checkpoint_best" Returns: configs (dict): epoch or step, lr and other meta info should be saved.

save_parameters(checkpoint_dir, ...[, ...])

Save checkpoint in best_n and latest_n.

load_best_parameters(model, optimizer=None, checkpoint_dir=None, checkpoint_path=None)[source]

Load a last model checkpoint from disk. Args:

model (Layer): model to load parameters. optimizer (Optimizer, optional): optimizer to load states if needed.

Defaults to None.

checkpoint_dir (str, optional): the directory where checkpoint is saved. checkpoint_path (str, optional): if specified, load the checkpoint

stored in the checkpoint_path(prefix) and the argument 'checkpoint_dir' will be ignored. Defaults to None.

Returns:

configs (dict): epoch or step, lr and other meta info should be saved.

load_latest_parameters(model, optimizer=None, checkpoint_dir=None, checkpoint_path=None)[source]

Load a last model checkpoint from disk. Args:

model (Layer): model to load parameters. optimizer (Optimizer, optional): optimizer to load states if needed.

Defaults to None.

checkpoint_dir (str, optional): the directory where checkpoint is saved. checkpoint_path (str, optional): if specified, load the checkpoint

stored in the checkpoint_path(prefix) and the argument 'checkpoint_dir' will be ignored. Defaults to None.

Returns:

configs (dict): epoch or step, lr and other meta info should be saved.

load_parameters(model, optimizer=None, checkpoint_dir=None, checkpoint_path=None, record_file='checkpoint_latest')[source]

Load a last model checkpoint from disk. Args:

model (Layer): model to load parameters. optimizer (Optimizer, optional): optimizer to load states if needed.

Defaults to None.

checkpoint_dir (str, optional): the directory where checkpoint is saved. checkpoint_path (str, optional): if specified, load the checkpoint

stored in the checkpoint_path(prefix) and the argument 'checkpoint_dir' will be ignored. Defaults to None.

record_file "checkpoint_latest" or "checkpoint_best"

Returns:

configs (dict): epoch or step, lr and other meta info should be saved.

save_parameters(checkpoint_dir, tag_or_iteration: Union[int, str], model: Layer, optimizer: Optional[Optimizer] = None, infos: Optional[dict] = None, metric_type='val_loss')[source]

Save checkpoint in best_n and latest_n.

Args:

checkpoint_dir (str): the directory where checkpoint is saved. tag_or_iteration (int or str): the latest iteration(step or epoch) number or tag. model (Layer): model to be checkpointed. optimizer (Optimizer, optional): optimizer to be checkpointed. infos (dict or None)): any info you want to save. metric_type (str, optional): metric type. Defaults to "val_loss".