I trained the model with matconvnet code, and convert the model to PyTorch from MatConvNet model with the tool https://github.com/albanie/pytorch-mcn 16, and the converted models can be download from http://www.robots.ox.ac.uk/~albanie/pytorch-models.html#pedestrian-alginment 17
https://github.com/albanie/pytorch-mcn/issues/1 9
I hope to load the net structure and modify parts of layers, and use the parameters of other layers in the converted model. How can I load the net structure of the model and its parameters with Pytorch from the pretrained pedestrian-alginment.pth?
I write the follow code, but it get the errors: I think the error arises from the wrong defined model variable? I should define a empty net object or how to correct it?
import torchvision.models as models
import torch
import torch.nn as nn

pretrained=False
model = models.resnet50(pretrained)
modelpath="/home/chengzi/Downloads/netvlad_v103/pre-trained-models/pedestrian_alignment.pth"
checkpoint = torch.load(modelpath)
net=model.load_state_dict(checkpoint)
print(net)

Traceback (most recent call last):
File "/home/chengzi/workspace/demo/model_s.py", line 13, in
net=model.load_state_dict(checkpoint)
File "/usr/local/lib/python3.5/dist-packages/torch/nn/modules/module.py", line 490, in load_state_dict
.format(name))
KeyError: 'unexpected key "conv1.bias" in state_dict'