utils/checkpoints.py
def restore_checkpoint(checkpoint_type: str, paths: Paths, model, optimizer, *,
                       name=None, create_if_missing=False):
    """Restores from a training session saved to disk.

    NOTE: The optimizer's state is placed on the same device as it's model
    parameters. Therefore, be sure you have done `model.to(device)` before
    calling this method.

    Args:
        paths:  Provides information about the different paths to use.
        model:  A `Tacotron` or `WaveRNN` model to save the parameters and buffers from.
        optimizer:  An optmizer to save the state of (momentum, etc).
        name:  If provided, will restore from a checkpoint with the given name.
            Otherwise, will restore from the latest weights and optimizer state
            as specified in `paths`.
        create_if_missing:  If `True`, will create the checkpoint if it doesn't
            yet exist, as well as update the files specified in `paths` that
            give the location of the current latest weights and optimizer state.
            If `False` and the checkpoint doesn't exist, will raise a
            `FileNotFoundError`.
    """

    weights_path, optim_path, checkpoint_path = \
        get_checkpoint_paths(checkpoint_type, paths)

    if name:
        path_dict = {
            'w': checkpoint_path/f'{name}_weights.pyt',
            'o': checkpoint_path/f'{name}_optim.pyt',
        }
        s = 'named'
    else:
        path_dict = {
            'w': weights_path,
            'o': optim_path
        }
        s = 'latest'

    num_exist = sum(p.exists() for p in path_dict.values())
    if num_exist == 2:
        # Checkpoint exists
        print(f'Restoring from {s} checkpoint...')
        print(f'Loading {s} weights: {path_dict["w"]}')
        model.load(path_dict['w'])
        print(f'Loading {s} optimizer state: {path_dict["o"]}')
        optimizer.load_state_dict(torch.load(path_dict['o']))
    elif num_exist == 1:
        print(f'Restoring from {s} checkpoint...')
        print(f'Loading {s} weights: {path_dict["w"]}')
        model.load(path_dict['w'])
        print(f'Creating new {s} optimizer state: {path_dict["o"]}')
        print(f'Saving {s} optimizer state: {path_dict["o"]}')
        torch.save(optimizer.state_dict(), path_dict['o'])
    elif create_if_missing:
        save_checkpoint(checkpoint_type, paths, model,
                        optimizer, name=name, is_silent=False)
    else:
        raise FileNotFoundError(f'The {s} checkpoint could not be found!')
Restores from a training session saved to disk.

    NOTE: The optimizer's state is placed on the same device as it's model
    parameters. Therefore, be sure you have done `model.to(device)` before
    calling this method.

    Args:
        paths:  Provides information about the different paths to use.
        model:  A `Tacotron` or `WaveRNN` model to save the parameters and buffers from.
        optimizer:  An optmizer to save the state of (momentum, etc).
        name:  If provided, will restore from a checkpoint with the given name.
            Otherwise, will restore from the latest weights and optimizer state
            as specified in `paths`.
        create_if_missing:  If `True`, will create the checkpoint if it doesn't
            yet exist, as well as update the files specified in `paths` that
            give the location of the current latest weights and optimizer state.
            If `False` and the checkpoint doesn't exist, will raise a
            `FileNotFoundError`.
    
Restores from a training session saved to disk.
NOTE: The optimizer's state is placed on the same device as it's model
parameters. Therefore, be sure you have done `model.to(device)` before
calling this method.
Restores from a training session saved to disk . NOTE : The optimizer ' s state is placed on the same device as it ' s model parameters . Therefore be sure you have done ` model . to ( device ) ` before calling this method .
def restore_checkpoint(checkpoint_type: str, paths: Paths, model, optimizer, *,
                       name=None, create_if_missing=False):
    weights_path, optim_path, checkpoint_path = \
        get_checkpoint_paths(checkpoint_type, paths)
    if name:
        path_dict = {
            'w': checkpoint_path/f'{name}_weights.pyt',
            'o': checkpoint_path/f'{name}_optim.pyt',
        }
        s = 'named'
    else:
        path_dict = {
            'w': weights_path,
            'o': optim_path
        }
        s = 'latest'
    num_exist = sum(p.exists() for p in path_dict.values())
    if num_exist == 2:
        print(f'Restoring from {s} checkpoint...')
        print(f'Loading {s} weights: {path_dict["w"]}')
        model.load(path_dict['w'])
        print(f'Loading {s} optimizer state: {path_dict["o"]}')
        optimizer.load_state_dict(torch.load(path_dict['o']))
    elif num_exist == 1:
        print(f'Restoring from {s} checkpoint...')
        print(f'Loading {s} weights: {path_dict["w"]}')
        model.load(path_dict['w'])
        print(f'Creating new {s} optimizer state: {path_dict["o"]}')
        print(f'Saving {s} optimizer state: {path_dict["o"]}')
        torch.save(optimizer.state_dict(), path_dict['o'])
    elif create_if_missing:
        save_checkpoint(checkpoint_type, paths, model,
                        optimizer, name=name, is_silent=False)
    else:
        raise FileNotFoundError(f'The {s} checkpoint could not be found!')
def restore_checkpoint ( checkpoint_type : str , paths : Paths , model , optimizer , * , name = None , create_if_missing = False ) : weights_path , optim_path , checkpoint_path = get_checkpoint_paths ( checkpoint_type , paths ) if name : path_dict = { 'w' : checkpoint_path / f'{name}_weights.pyt' , 'o' : checkpoint_path / f'{name}_optim.pyt' , } s = 'named' else : path_dict = { 'w' : weights_path , 'o' : optim_path } s = 'latest' num_exist = sum ( p . exists ( ) for p in path_dict . values ( ) ) if num_exist == 2 : print ( f'Restoring from {s} checkpoint...' ) print ( f'Loading {s} weights: {path_dict["w"]}' ) model . load ( path_dict [ 'w' ] ) print ( f'Loading {s} optimizer state: {path_dict["o"]}' ) optimizer . load_state_dict ( torch . load ( path_dict [ 'o' ] ) ) elif num_exist == 1 : print ( f'Restoring from {s} checkpoint...' ) print ( f'Loading {s} weights: {path_dict["w"]}' ) model . load ( path_dict [ 'w' ] ) print ( f'Creating new {s} optimizer state: {path_dict["o"]}' ) print ( f'Saving {s} optimizer state: {path_dict["o"]}' ) torch . save ( optimizer . state_dict ( ) , path_dict [ 'o' ] ) elif create_if_missing : save_checkpoint ( checkpoint_type , paths , model , optimizer , name = name , is_silent = False ) else : raise FileNotFoundError ( f'The {s} checkpoint could not be found!' )
Restores from a training session saved to disk.
Restores from a training session saved to disk .
"""Restores from a training session saved to disk.

    NOTE: The optimizer's state is placed on the same device as it's model
    parameters. Therefore, be sure you have done `model.to(device)` before
    calling this method.

    Args:
        paths:  Provides information about the different paths to use.
        model:  A `Tacotron` or `WaveRNN` model to save the parameters and buffers from.
        optimizer:  An optmizer to save the state of (momentum, etc).
        name:  If provided, will restore from a checkpoint with the given name.
            Otherwise, will restore from the latest weights and optimizer state
            as specified in `paths`.
        create_if_missing:  If `True`, will create the checkpoint if it doesn't
            yet exist, as well as update the files specified in `paths` that
            give the location of the current latest weights and optimizer state.
            If `False` and the checkpoint doesn't exist, will raise a
            `FileNotFoundError`.
    """ # Checkpoint exists
checkpoint_type
str
paths
Paths
Provides information about the different paths to use.
Provides information about the different paths to use .
model
A `Tacotron` or `WaveRNN` model to save the parameters and buffers from.
A ` Tacotron ` or ` WaveRNN ` model to save the parameters and buffers from .
optimizer
An optmizer to save the state of (momentum, etc).
An optmizer to save the state of ( momentum etc ) .
name
If provided, will restore from a checkpoint with the given name.
Otherwise, will restore from the latest weights and optimizer state
as specified in `paths`.
If provided will restore from a checkpoint with the given name . Otherwise will restore from the latest weights and optimizer state as specified in ` paths ` .
create_if_missing
If `True`, will create the checkpoint if it doesn't
yet exist, as well as update the files specified in `paths` that
give the location of the current latest weights and optimizer state.
If `False` and the checkpoint doesn't exist, will raise a
`FileNotFoundError`.
If ` True ` will create the checkpoint if it doesn ' t yet exist as well as update the files specified in ` paths ` that give the location of the current latest weights and optimizer state . If ` False ` and the checkpoint doesn ' t exist will raise a ` FileNotFoundError ` .