How load all pretrained model as part of new mode?


How can I load a pre-trained model as part of my new model, which is built upon the old model and add some new layers to it?

e.g . I add some layers to the resnet to build a new model, so how can i use the pretrained model of the resnet?

thank you in advance!

I solved it.

premodel = torch.load(‘pre.pth’)
new_model_dict = newmodel.state_dict()

for k, v in premodel:
    new_model_dict [k] = v