| 120 | '{}/pth/model_{}.pth'.format(self.config.OUTPUT.DIR, epoch)) |
| 121 | |
| 122 | def load_checkpoint(self, weight_path, resume=False): |
| 123 | checkpoint = torch.load(weight_path) |
| 124 | # load model parameters |
| 125 | try: |
| 126 | model_dict = checkpoint["state_dict"] |
| 127 | except: |
| 128 | model_dict = checkpoint # for pointnetvlad |
| 129 | try: |
| 130 | self.model.load_state_dict(model_dict) |
| 131 | except: |
| 132 | from collections import OrderedDict |
| 133 | model_dict = OrderedDict() |
| 134 | for key, value in checkpoint["state_dict"].items(): |
| 135 | new_key = key.split('module.')[-1] |
| 136 | model_dict[new_key] = value |
| 137 | self.model.load_state_dict(model_dict) |
| 138 | log_print("Load models from {}!".format(weight_path), 'g') |
| 139 | # load optimizer parameters |
| 140 | if resume: |
| 141 | self.optimizer.load_state_dict(checkpoint["optimizer"]) |
| 142 | log_print("Load optimizer parameters from {}!".format(weight_path), 'g') |
| 143 | return checkpoint["epoch"] |
| 144 | else: |
| 145 | return |
| 146 | |
| 147 | |
| 148 | #!=======================================================================# |