practical-pytorch icon indicating copy to clipboard operation
practical-pytorch copied to clipboard

How to save and load train model and use it for evaluation

Open j07nikita opened this issue 6 years ago • 2 comments

j07nikita avatar Mar 23 '19 11:03 j07nikita

To save a model, you can use the following snippet:

torch.save(model.state_dict(), "Models/RES50.pth")

Here, I save my model in the directory Models with the name RES50

While evaluation, you can load your model using the following:

model = Neural_Network()
model.load_state_dict(torch.load('Models/RES50.pth'))

Here, I initialized my model and then loaded the parameters of the model RES50 which was lying in the directory Models.

Hope that helps!

dhananjaisharma10 avatar Apr 12 '19 21:04 dhananjaisharma10

"torch.save(model.state_dict(), "Models/RES50.pth")" In that, we need to define the class 'myModel' in order to create 'model' object. Could you please share the script how to define a model class? Thank in advance!

SuMyo avatar Jan 21 '20 05:01 SuMyo