Search code examples
pythonmachine-learningpytorchpredictiontorch

Viewing Pytorch weights from a *.pth file


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)

Solution

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

    (Verify and confirm)