after training the model, I use torch.save
to save the model with .pth
format.
And in another python file, I try to use torch.load
to load the model and do the prediction, but seems like it retrain the model and then do the prediction,
Can someone explains that for me ?
What do you mean by “but seems like it retrain the model and then do the prediction”?
After loading your model, you usually set it to evaluation mode using model.eval()
, since some layers behave differently.
BatchNorm
and Dropout
are examples of the different behavior between training and evaluation.
Could you explain a bit more?
thanks for your reply, for e.g., I trained a model with dataset mnist, while training, I set 5 epoch, and print something after each epoch, and the end of the code, I use torch. save(cnn,'path')
to save the model with .pth
format. And in another python file, when I use model = torch.load('path')
to load the model, it prints from the first epoch (train again?). So that’s the point I’m confused with.
Thanks again for your reply.
I’ll try now, thanks for the information.
Hi, I know it’s been years, but do u find a solution for this? I’m stuck with the same issue although I did load the state_dict as the documentation stated.