Last active
          January 22, 2020 22:31 
        
      - 
      
- 
        Save vsay01/45dfced69687077be53dbdd4987b6b17 to your computer and use it in GitHub Desktop. 
    Save checkpoint in PyTorch
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | 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