简体   繁体   English

从 *.pth 文件中查看 Pytorch 权重

[英]Viewing Pytorch weights from a *.pth file

I have a .pth file created with Pytorch with weights.我有一个用 Pytorch 创建的带有权重的.pth文件。 How would I be able to view the weights from this file?我怎样才能从这个文件中查看权重?

I tried this code to load and view but it was not working (as a newbie, I might be entirely wrong)-我试过这段代码来加载和查看,但它不起作用(作为新手,我可能完全错了)-

import torch
import torchvision.models as models

torch.save('weights\kharif_crops_final.pth')

models.load_state_dict(torch.load('weights\kharif_crops_final.pth'))
models.eval()
print(models)
import torch

model = torch.load('path')
print(model)

(Verify and confirm) (验证并确认)

PATH = 'weights\kharif_crops_final.pth' state = {'model': model.state_dict()} torch.save(state, PATH) model.load_state_dict(torch.load(PATH)['model']) # print weights for k, v in model.named_parameters(): print(k, v)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM