BobLiu20 / YOLOv3_PyTorch

Full implementation of YOLOv3 in PyTorch
624 stars 191 forks source link

Weights in checkpoint are on a different namespace than the weights the network expects. #4

Closed joaqo closed 6 years ago

joaqo commented 6 years ago

Hi, been trying to load the weights in the checkpoint you provide, but I get the following (abbreviated) error message:

RuntimeError: Error(s) in loading state_dict for ModelMain: Missing key(s) in state_dict: "backbone.conv1.weight", "backbone.bn1.weight", "backbone.bn1.bias", "backbone.bn1.running_mean", "backbone.bn1.running_var", "backbone.layer1.ds_conv.weight", "backbone.layer1.ds_bn.weight", "backbone.layer1.ds_bn.bias", "backbone.layer1.ds_bn.running_mean", "backbone.layer1.ds_bn.running_var", "backb one.layer1.residual_0.conv1.weight", "backbone.layer1.residual_0.bn1.weight", "backbone.layer1.residual_0.bn1.bias", "backbone.layer1.residual_0.bn1.running_mean", "backbone.layer1.residual_0.bn1.running_var", "backbone.layer1.residual_0.conv2.weight", "backbone.layer1.residual_0.bn2.weight", "backbone.layer1.residual_0.bn2.bias", "backbon e.layer1.residual_0.bn2.running_mean"...

Unexpected key(s) in state_dict: "module.backbone.conv1.weight", "module.backbone.bn1.weight", "module.backbone.bn1.bias", "module.backbone.bn1.running_mean", "module.backbone.bn1.running_var", "module.backbone.layer1.ds_conv.weight", "module.backbone.layer1.ds_bn.weight", "module.backbone.layer1.ds_bn.bias", "module.backbone.layer1.ds_bn.running_mean", "module.backbone.layer1.ds_bn.running_var", "module.backbone.layer1.residual_0.conv1.weight", "module.backbone.layer1.residual_0.bn1.weight", "module.backbone.layer1.residual_0.bn1.bias", "module.backbone.layer1.residual_0.bn1.running_mean", "module.backbone.layer1.residual_0.bn1.running_var", "module.backbone.layer1.residual_0.conv2.weight", "module.backbone.layer1.residual_0.bn2.weight", "module.backbone.layer1.residual_0.bn2.bias", "module.backbone.layer1.residual_0.bn2.running_mean"...

It looks as if the checkpoint has all of its weights inside the module namespace, while the model doesn't, is there a particular reason for this?

Thanks!

joaqo commented 6 years ago

Turns out I had removed net = nn.DataParallel(net) from the code and for some reason it causes this bug. My bad.