| 142 | |
| 143 | |
| 144 | def Load_model(args, model, model_refine=None): |
| 145 | model_paths = sorted(glob.glob(os.path.join(args.previous_dir, '*.pth'))) |
| 146 | model_path = model_paths[0] |
| 147 | print(model_path) |
| 148 | |
| 149 | pre_dict = torch.load(model_path) |
| 150 | model_dict = model.state_dict() |
| 151 | |
| 152 | state_dict = {k: v for k, v in pre_dict.items() if k in model_dict.keys()} |
| 153 | model_dict.update(state_dict) |
| 154 | model.load_state_dict(model_dict) |
| 155 | |
| 156 | # Reload refine model |
| 157 | if args.refine_reload: |
| 158 | refine_path = model_paths[1] |
| 159 | print(refine_path) |
| 160 | |
| 161 | pre_dict_refine = torch.load(refine_path) |
| 162 | |
| 163 | refine_dict = model_refine.state_dict() |
| 164 | state_dict = {k: v for k, v in pre_dict_refine.items() if k in refine_dict.keys()} |
| 165 | refine_dict.update(state_dict) |
| 166 | model_refine.load_state_dict(refine_dict) |
| 167 | |
| 168 | |
| 169 | |