fix model loading
This commit is contained in:
@@ -35,6 +35,8 @@ def load_model(model, checkpoint, optimizer=None, iteration=''):
|
|||||||
# list of checkpoint files in the folder checkpoints
|
# list of checkpoint files in the folder checkpoints
|
||||||
checkpoints = [os.path.join(checkpoint, f) for f in os.listdir(checkpoint) if f.endswith(f'{iteration}.pt')]
|
checkpoints = [os.path.join(checkpoint, f) for f in os.listdir(checkpoint) if f.endswith(f'{iteration}.pt')]
|
||||||
checkpoint = torch.load(checkpoints[-1])
|
checkpoint = torch.load(checkpoints[-1])
|
||||||
|
iteration = checkpoints[-1].split('_')[-1].split('.')[0]
|
||||||
model.load_state_dict(checkpoint['model'])
|
model.load_state_dict(checkpoint['model'])
|
||||||
if optimizer is not None: optimizer.load_state_dict(checkpoint['optimizer'])
|
if optimizer is not None: optimizer.load_state_dict(checkpoint['optimizer'])
|
||||||
|
return int(iteration) if iteration != '' else 0
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user