如何加载把深度学习保存的模型.pth或者.module打印出来,保存在txt文件中

代码如下,只需要把模型文件的路径pthfile更改一下即可.

import torch

pthfile = r'/home/bob/jj/pysot/snapshot_/checkpoint_e27.pth'
net = torch.load(pthfile, map_location='cpu')
net = dict(net)

with open('test.txt', 'a') as file0:
    print(net, file=file0)

这样模型信息就都保存在test.txt文件中了.
(可以点个赞不, ^ _ ^ )

你可能感兴趣的:(深度学习)