pytorch_模型参数-保存,加载,打印

时间:2019-12-12 17:13:41   收藏:0   阅读:530

1.保存模型参数(gen-我自己的模型名字)

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

2.加载模型参数

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

3.打印查看模型参数

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

打印结果:

技术分享图片

 

 

原文:https://www.cnblogs.com/shuangcao/p/12030206.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!