Load all the networks from the disk. Parameters: epoch (int) -- current epoch; used in the file name '%s_net_%s.pth' % (epoch, name)
(self, epoch)
| 172 | self.__patch_instance_norm_state_dict(state_dict, getattr(module, key), keys, i + 1) |
| 173 | |
| 174 | def load_networks(self, epoch): |
| 175 | """Load all the networks from the disk. |
| 176 | |
| 177 | Parameters: |
| 178 | epoch (int) -- current epoch; used in the file name '%s_net_%s.pth' % (epoch, name) |
| 179 | """ |
| 180 | for name in self.model_names: |
| 181 | if isinstance(name, str): |
| 182 | load_filename = '%s_net_%s.pth' % (epoch, name) |
| 183 | load_path = os.path.join(self.save_dir, load_filename) |
| 184 | net = getattr(self, 'net' + name) |
| 185 | if isinstance(net, torch.nn.DataParallel): |
| 186 | net = net.module |
| 187 | print('loading the model from %s' % load_path) |
| 188 | # if you are using PyTorch newer than 0.4 (e.g., built from |
| 189 | # GitHub source), you can remove str() on self.device |
| 190 | state_dict = torch.load(load_path, map_location=str(self.device)) |
| 191 | if hasattr(state_dict, '_metadata'): |
| 192 | del state_dict._metadata |
| 193 | |
| 194 | # patch InstanceNorm checkpoints prior to 0.4 |
| 195 | for key in list(state_dict.keys()): # need to copy keys here because we mutate in loop |
| 196 | self.__patch_instance_norm_state_dict(state_dict, net, key.split('.')) |
| 197 | net.load_state_dict(state_dict, strict=False) |
| 198 | |
| 199 | def print_networks(self, verbose): |
| 200 | """Print the total number of parameters in the network and (if verbose) network architecture |
no test coverage detected