| 66 | |
| 67 | #加载模型 |
| 68 | def load_checkpoint(checkpoint_file, model, optimizer, lr): |
| 69 | print("=> Loading checkpoint") |
| 70 | checkpoint = torch.load(checkpoint_file, map_location="cuda") |
| 71 | model.load_state_dict(checkpoint["state_dict"]) |
| 72 | optimizer.load_state_dict(checkpoint["optimizer"]) |
| 73 | |
| 74 | # If we don't do this then it will just have learning rate of old checkpoint |
| 75 | # and it will lead to many hours of debugging \: |
| 76 | for param_group in optimizer.param_groups: |
| 77 | param_group["lr"] = lr |
| 78 | |
| 79 | |
| 80 | def seed_everything(seed=42): |