which is from pytorch, how i can use the weights in this model to update my model in base_.load_state_dict(resnet_weights, strict=False)
like i did above? is it even possible?
I see, thank you for your answer.
I have a follow up question, let say my model is model = models.resnet101(pretrained = True) and then I finetune it, and then want to save it and load it again.
Do you suggest to save and load it like: torch.save(the_model.state_dict(), PATH)
the_model.load_state_dict(torch.load(PATH))
or you have other suggestion?
in link
it says to do the_model = TheModelClass(*args, **kwargs)
first, but i dont get why and what it means by TheModelClass
Yes what you want to do here is fine.
What it means is that creation of the model and loading of the weights are two different things: You don’t save an nn.Module with all it’s weights. You save the weights on one side with .state_dict() and the module’s info on the other side by saving the arguments to create it.
Sorry it was not clear “You don’t” means “You should not”.
Saving python class instances like models breaks so easily in so many levels that you have a very high chance to end up with an object that you will never be able to load again
You can do it, but you shouldn’t so I won’t tell you how to do it