Can you load a pytorch saved model without knowing its parameters? #752
Unanswered
thecaptain2000
asked this question in
Q&A
Replies: 1 comment
-
Yeah there is another way but its more complicated than this method you should you this method as the sir said |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Is it possible to load a saved model without having to communicate the (now useless) parameters which have been used for training it?
at the end of Chapter 3, we exercise with saving and loading the TinyVGG model.
IN the model definition, we do the following:
class TynyVGG(nn.Module):
def init(self, input_shape: int, hidden_units: int, output_shape: int):
...
once the model is trained, the input_shape: hidden_units and output_shape should be redundant (or irrelevant) to the user, as to change them, the user should re train the model. The problem is in order to load the model from file, we need to know those parameters first as we need to:
model_2_loaded = TynyVGG(input_shape=1, hidden_units=30, output_shape=len(class_names)).to(device)
to be able to load the model parameters using:
model_2_loaded.load_state_dict(torch.load(f=MODEL_SAVE_PATH))
Is there a way to load a model without having to communicate the user, the parameters the model was built with?
I was thinking of overloading the constructor and provide a "LoadFromFile" method, is there a better solution?
Beta Was this translation helpful? Give feedback.
All reactions