Save PyTorch Model for Evaluation

In the documentation is this part of the code:

However, how does the script knows the “TheModelClass” since here it does not say that we have to import the model class?

Note that in documentation there are two methods of saving the model. If you have access to created model class, you can save only the states/weights in form of dictionary. But you then are required to have the code of the class → next you create “empty” model, and apply the weights.
Second method saves everything, including the model structure. This can be found in documentation here: Saving and Loading Models — PyTorch Tutorials 1.11.0+cu102 documentation

I hope, I have helped and understood you question correctly.

1 Like