MCPcopy Create free account
hub / github.com/TorchSSL/TorchSSL / save_model

Method save_model

models/vat/vat.py:224–240  ·  view source on GitHub ↗
(self, save_name, save_path)

Source from the content-addressed store, hash-verified

222 return {'eval/loss': total_loss / total_num, 'eval/top-1-acc': top1, 'eval/top-5-acc': top5}
223
224 def save_model(self, save_name, save_path):
225 save_filename = os.path.join(save_path, save_name)
226 # copy EMA parameters to ema_model for saving with model as temp
227 self.model.eval()
228 self.ema.apply_shadow()
229 ema_model = self.model.state_dict()
230 self.ema.restore()
231 self.model.train()
232
233 torch.save({'model': self.model.state_dict(),
234 'optimizer': self.optimizer.state_dict(),
235 'scheduler': self.scheduler.state_dict(),
236 'it': self.it + 1,
237 'ema_model': ema_model},
238 save_filename)
239
240 self.print_fn(f"model saved: {save_filename}")
241
242 def load_model(self, load_path):
243 checkpoint = torch.load(load_path)

Callers 14

trainMethod · 0.95
main_workerFunction · 0.45
main_workerFunction · 0.45
main_workerFunction · 0.45
main_workerFunction · 0.45
main_workerFunction · 0.45
main_workerFunction · 0.45
main_workerFunction · 0.45
main_workerFunction · 0.45
main_workerFunction · 0.45
main_workerFunction · 0.45
main_workerFunction · 0.45

Calls 3

apply_shadowMethod · 0.80
restoreMethod · 0.80
trainMethod · 0.45

Tested by

no test coverage detected