0

I have a CNN model and I want to save it and load it for prediction in different tab. But I am confused whether the model.evulotion part is included in the part I will save. And I don't know if it would be better to use Model.checkpoint or model.save to save and load. Is there anyone have an idea ? Thank you in advance

I'm in dilemma about using both of them so I've use it.

Gülsüm
  • 3
  • 2

1 Answers1

0

Using model.eval() just tells the PyTorch model to use mean values for batch normalisation, and deactivates the dropout layers. You can save your model without using model.eval() as it will not affect the performance. While saving model, saving model's state dictionary is preferred. This can be done as shown:

#declare class of model here
model = NeuralNetwork()
#add training code below
...
#saving model, the model will be saved at the intermediateWeightPath location
intermediateWeightPath = "./bestmodel.pth"
torch.save(model.state_dict(), intermediateWeightPath)
Azhan Mohammed
  • 340
  • 2
  • 8
  • Oh I mean “ When I Need to save my model, before or after using test data (sorry for my bad English ) and My teacher Said pickle module can be used for saving. But pickle is for ML models not DL models as I know – Gülsüm Oct 31 '22 at 14:00
  • Yeah you do not need to use ```model.eval()``` before saving your model. As for the pickle file, usually use the inbuilt model saving functions, rather than saving a model as a pickle file. – Azhan Mohammed Nov 01 '22 at 07:17
  • Thank u so much I'm grateful for answering my questions – Gülsüm Nov 01 '22 at 12:08