pytorch_模型參數-保存,加載,打印

1.保存模型參數(gen-我本身的模型名字)python

torch.save(self.gen.state_dict(), os.path.join(self.gen_save_path, 'gen_%d.pth'%step)) 

2.加載模型參數spa

self.gen.load_state_dict(torch.load(os.path.join(self.gen_save_path, 'gen_%d.pth'%step),map_location='cpu')) 

3.打印查看模型參數code

 pthfile = r'./trained_models\64\models\gen_97000.pth' net = torch.load(pthfile,map_location='cpu') print(net)

打印結果:blog

相關文章
相關標籤/搜索