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

相关文章
相关标签/搜索