I have a .pth file created with Pytorch with weights. 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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.