[英]Saving the weights of a Pytorch .pth model into a .txt or .json
[英]Viewing Pytorch weights from a *.pth file
我有一個用 Pytorch 創建的帶有權重的.pth文件。 我怎樣才能從這個文件中查看權重?
我試過這段代碼來加載和查看,但它不起作用(作為新手,我可能完全錯了)-
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)
(驗證並確認)
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.