torchcv: Key mismatch while loading the model?

I am having issue loading the trained checkpoint to FPNSSD512 model. How can I fix that?

RuntimeError: Error(s) in loading state_dict for FPNSSD512:
	Missing key(s) in state_dict: "fpn.conv1.weight", "fpn.bn1.running_var", "fpn.bn1.bias", "fpn.bn1.running_mean", "fpn.bn1.weight", "fpn.layer1.0.conv1.weight", "fpn.layer1.0.bn1.running_var", "fpn.layer1.0.bn1.bias", "fpn.layer1.0.bn1.running_mean", "fpn.layer1.0.bn1.weight", "fpn.layer1.0.conv2.weight", "fpn.layer1.0.bn2.running_var", "fpn.layer1.0.bn2.bias", 

        Unexpected key(s) in state_dict: "module.fpn.conv1.weight", "module.fpn.bn1.weight", "module.fpn.bn1.bias", "module.fpn.bn1.running_mean", "module.fpn.bn1.running_var", "module.fpn.layer1.0.conv1.weight"

About this issue

Most upvoted comments

If you want to load the weights after DataParallel use: net.module.load_state_dict(pertained_weights) If you want to load the weights before DataParallel use: net.load_state_dict(pertained_weights)

@ahkarami I uploaded the sgd training and eval log. And with sgd, I can only got aound 76% mAP now. The pretrained model was in here.

@ahkarami Please check my code. https://github.com/silkylove/ObjectDetection/tree/master/example/fpnssd I also uploaded the training log with adam with 100 epochs which could get 73.95mAP until now. I am now training SGD with 200 epochs on that which I think would get higher mAP, I will release the training log later. Also, you can uncommen this line in eval.py https://github.com/silkylove/ObjectDetection/blob/master/example/fpnssd/eval.py#L25 to got his pertrained model’s performence (about 56mAP). And make sure not to use dataparallel.

Dear @ahkarami , Ok, I will release the code after I get similar performence compared to his pretrained fpnssd512 model.

Dear @ahkarami , I think the pretrained fpnssd model provided by @kuangliu is not the same as /models/fpnssd/net.py. Actually, he said that he just replaced vgg16 by fpn50 in ssd512 which is /models/ssd/net.py. So you could not use the model created by /models/fpnssd/net.py to load the wights in /models/ssd/net.py as the keys are not matched. The solution to use his provided pretrained model is to train his ssd512 model with fpn50 not fpnssd512 model in /models/fpnssd/net.py. Also, it seems that he did not put all of his examples on this github or he delete something before pushing.