Skip to content

Instantly share code, notes, and snippets.

@vsay01
Last active January 22, 2020 22:31
Show Gist options
  • Save vsay01/45dfced69687077be53dbdd4987b6b17 to your computer and use it in GitHub Desktop.
Save vsay01/45dfced69687077be53dbdd4987b6b17 to your computer and use it in GitHub Desktop.
Save checkpoint in PyTorch
def save_ckp(state, is_best, checkpoint_path, best_model_path):
"""
state: checkpoint we want to save
is_best: is this the best checkpoint; min validation loss
checkpoint_path: path to save checkpoint
best_model_path: path to save best model
"""
f_path = checkpoint_path
# save checkpoint data to the path given, checkpoint_path
torch.save(state, f_path)
# if it is a best model, min validation loss
if is_best:
best_fpath = best_model_path
# copy that checkpoint file to best path given, best_model_path
shutil.copyfile(f_path, best_fpath)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment