| 15 | |
| 16 | |
| 17 | def process_checkpoint(in_file, out_file): |
| 18 | checkpoint = torch.load(in_file, map_location='cpu') |
| 19 | # remove optimizer for smaller file size |
| 20 | if 'optimizer' in checkpoint: |
| 21 | del checkpoint['optimizer'] |
| 22 | # if it is necessary to remove some sensitive data in checkpoint['meta'], |
| 23 | # add the code here. |
| 24 | torch.save(checkpoint, out_file) |
| 25 | sha = subprocess.check_output(['sha256sum', out_file]).decode() |
| 26 | final_file = out_file.rstrip('.pth') + '-{}.pth'.format(sha[:8]) |
| 27 | subprocess.Popen(['mv', out_file, final_file]) |
| 28 | |
| 29 | |
| 30 | def main(): |