Https://discuss.pytorch.org/t/how-to-load-part-of-pre-trained-model/1113/33

Hi, I have a multi-input model with 3 parallel resnet and I want to just load one of them. I have no idea that how I could make a dictionary of the name of those layers that I want to use and use the code in this forum, How to load part of pre trained model? - #33 by MariosOreo.

for key in model_dict:
if ‘resnet1’ in key:
# print (key)
pretrained_dict.append(key)

Could you explain your use case a bit more?
Are you using a custom module, which contains 3 separate resnets?
If so, you should be able to access the desired submodel directly e.g. via: model.resnet1.state_dict().

1 Like