Open margokhokhlova opened 2 years ago
Please, can you advice what I might be doing wrong? I am trying to run the eval script, I changed the path to the saved weigths but I am getting this:
RuntimeError: Error(s) in loading state_dict for EncoderNet: Missing key(s) in state_dict: "conv.weight", "conv.bias", "bn.weight", "bn.bias", "bn.running_mean", "bn.running_var", "en_layer1.0.conv1.weight", "en_layer1.0.conv1.bias", "en_layer1.0.bn1.weight", "en_layer1.0.bn1.bias", "en_layer1.0.bn1.running_mean", "en_layer1.0.bn1.running_var", "en_layer1.0.conv2.weight", "en_layer1.0.conv2.bias", "en_layer1.0.bn2.weight", "en_layer1.0.bn2.bias", "en_layer1.0.bn2.running_mean", "en_layer1.0.bn2.running_var", "en_layer2.0.conv1.weight", "en_layer2.0.conv1.bias", "en_layer2.0.bn1.weight", "en_layer2.0.bn1.bias", "en_layer2.0.bn1.running_mean", "en_layer2.0.bn1.running_var", "en_layer2.0.conv2.weight", "en_layer2.0.conv2.bias", "en_layer2.0.bn2.weight", "en_layer2.0.bn2.bias", "en_layer2.0.bn2.running_mean", "en_layer2.0.bn2.running_var", "en_layer2.0.downsample.0.weight", "en_layer2.0.downsample.0.bias", "en_layer2.0.downsample.1.weight", "en_layer2.0.downsample.1.bias", "en_layer2.0.downsample.1.running_mean", "en_layer2.0.downsample.1.running_var", "en_layer3.0.conv1.weight", "en_layer3.0.conv1.bias", "en_layer3.0.bn1.weight", "en_layer3.0.bn1.bias", "en_layer3.0.bn1.running_mean", "en_layer3.0.bn1.running_var", "en_layer3.0.conv2.weight", "en_layer3.0.conv2.bias", "en_layer3.0.bn2.weight", "en_layer3.0.bn2.bias", "en_layer3.0.bn2.running_mean", "en_layer3.0.bn2.running_var", "en_layer3.0.downsample.0.weight", "en_layer3.0.downsample.0.bias", "en_layer3.0.downsample.1.weight", "en_layer3.0.downsample.1.bias", "en_layer3.0.downsample.1.running_mean", "en_layer3.0.downsample.1.running_var", "en_layer4.0.conv1.weight", "en_layer4.0.conv1.bias", "en_layer4.0.bn1.weight", "en_layer4.0.bn1.bias", "en_layer4.0.bn1.running_mean", "en_layer4.0.bn1.running_var", "en_layer4.0.conv2.weight", "en_layer4.0.conv2.bias", "en_layer4.0.bn2.weight", "en_layer4.0.bn2.bias", "en_layer4.0.bn2.running_mean", "en_layer4.0.bn2.running_var", "en_layer4.0.downsample.0.weight", "en_layer4.0.downsample.0.bias", "en_layer4.0.downsample.1.weight", "en_layer4.0.downsample.1.bias", "en_layer4.0.downsample.1.running_mean", "en_layer4.0.downsample.1.running_var", "en_layer5.0.conv1.weight", "en_layer5.0.conv1.bias", "en_layer5.0.bn1.weight", "en_layer5.0.bn1.bias", "en_layer5.0.bn1.running_mean", "en_layer5.0.bn1.running_var", "en_layer5.0.conv2.weight", "en_layer5.0.conv2.bias", "en_layer5.0.bn2.weight", "en_layer5.0.bn2.bias", "en_layer5.0.bn2.running_mean", "en_layer5.0.bn2.running_var", "en_layer5.0.downsample.0.weight", "en_layer5.0.downsample.0.bias", "en_layer5.0.downsample.1.weight", "en_layer5.0.downsample.1.bias", "en_layer5.0.downsample.1.running_mean", "en_layer5.0.downsample.1.running_var", "en_layer5.1.conv1.weight", "en_layer5.1.conv1.bias", "en_layer5.1.bn1.weight", "en_layer5.1.bn1.bias", "en_layer5.1.bn1.running_mean", "en_layer5.1.bn1.running_var", "en_layer5.1.conv2.weight", "en_layer5.1.conv2.bias", "en_layer5.1.bn2.weight", "en_layer5.1.bn2.bias", "en_layer5.1.bn2.running_mean", "en_layer5.1.bn2.running_var". Unexpected key(s) in state_dict: "module.conv.weight", "module.conv.bias", "module.bn.weight", "module.bn.bias", "module.bn.running_mean", "module.bn.running_var", "module.en_layer1.0.conv1.weight", "module.en_layer1.0.conv1.bias", "module.en_layer1.0.bn1.weight", "module.en_layer1.0.bn1.bias", "module.en_layer1.0.bn1.running_mean", "module.en_layer1.0.bn1.running_var", "module.en_layer1.0.conv2.weight", "module.en_layer1.0.conv2.bias", "module.en_layer1.0.bn2.weight", "module.en_layer1.0.bn2.bias", "module.en_layer1.0.bn2.running_mean", "module.en_layer1.0.bn2.running_var", "module.en_layer2.0.conv1.weight", "module.en_layer2.0.conv1.bias", "module.en_layer2.0.bn1.weight", "module.en_layer2.0.bn1.bias", "module.en_layer2.0.bn1.running_mean", "module.en_layer2.0.bn1.running_var", "module.en_layer2.0.conv2.weight", "module.en_layer2.0.conv2.bias", "module.en_layer2.0.bn2.weight", "module.en_layer2.0.bn2.bias", "module.en_layer2.0.bn2.running_mean", "module.en_layer2.0.bn2.running_var", "module.en_layer2.0.downsample.0.weight", "module.en_layer2.0.downsample.0.bias", "module.en_layer2.0.downsample.1.weight", "module.en_layer2.0.downsample.1.bias", "module.en_layer2.0.downsample.1.running_mean", "module.en_layer2.0.downsample.1.running_var", "module.en_layer3.0.conv1.weight", "module.en_layer3.0.conv1.bias", "module.en_layer3.0.bn1.weight", "module.en_layer3.0.bn1.bias", "module.en_layer3.0.bn1.running_mean", "module.en_layer3.0.bn1.running_var", "module.en_layer3.0.conv2.weight", "module.en_layer3.0.conv2.bias", "module.en_layer3.0.bn2.weight", "module.en_layer3.0.bn2.bias", "module.en_layer3.0.bn2.running_mean", "module.en_layer3.0.bn2.running_var", "module.en_layer3.0.downsample.0.weight", "module.en_layer3.0.downsample.0.bias", "module.en_layer3.0.downsample.1.weight", "module.en_layer3.0.downsample.1.bias", "module.en_layer3.0.downsample.1.running_mean", "module.en_layer3.0.downsample.1.running_var", "module.en_layer4.0.conv1.weight", "module.en_layer4.0.conv1.bias", "module.en_layer4.0.bn1.weight", "module.en_layer4.0.bn1.bias", "module.en_layer4.0.bn1.running_mean", "module.en_layer4.0.bn1.running_var", "module.en_layer4.0.conv2.weight", "module.en_layer4.0.conv2.bias", "module.en_layer4.0.bn2.weight", "module.en_layer4.0.bn2.bias", "module.en_layer4.0.bn2.running_mean", "module.en_layer4.0.bn2.running_var", "module.en_layer4.0.downsample.0.weight", "module.en_layer4.0.downsample.0.bias", "module.en_layer4.0.downsample.1.weight", "module.en_layer4.0.downsample.1.bias", "module.en_layer4.0.downsample.1.running_mean", "module.en_layer4.0.downsample.1.running_var", "module.en_layer5.0.conv1.weight", "module.en_layer5.0.conv1.bias", "module.en_layer5.0.bn1.weight", "module.en_layer5.0.bn1.bias", "module.en_layer5.0.bn1.running_mean", "module.en_layer5.0.bn1.running_var", "module.en_layer5.0.conv2.weight", "module.en_layer5.0.conv2.bias", "module.en_layer5.0.bn2.weight", "module.en_layer5.0.bn2.bias", "module.en_layer5.0.bn2.running_mean", "module.en_layer5.0.bn2.running_var", "module.en_layer5.0.downsample.0.weight", "module.en_layer5.0.downsample.0.bias", "module.en_layer5.0.downsample.1.weight", "module.en_layer5.0.downsample.1.bias", "module.en_layer5.0.downsample.1.running_mean", "module.en_layer5.0.downsample.1.running_var", "module.en_layer5.1.conv1.weight", "module.en_layer5.1.conv1.bias", "module.en_layer5.1.bn1.weight", "module.en_layer5.1.bn1.bias", "module.en_layer5.1.bn1.running_mean", "module.en_layer5.1.bn1.running_var", "module.en_layer5.1.conv2.weight", "module.en_layer5.1.conv2.bias", "module.en_layer5.1.bn2.weight", "module.en_layer5.1.bn2.bias", "module.en_layer5.1.bn2.running_mean", "module.en_layer5.1.bn2.running_var".
I have the same error
Add strict=False attribute to load_state_dict().
model_en.load_state_dict(torch.load('model_en.pkl'), strict=False)
model_de.load_state_dict(torch.load('model_de.pkl'), strict=False)
model_class.load_state_dict(torch.load('model_class.pkl'), strict=False)
You can replace the following code:
model_en.load_state_dict(torch.load('model_en.pkl'))
model_de.load_state_dict(torch.load('model_de.pkl'))
model_class.load_state_dict(torch.load('model_class.pkl'))
with:
def remove_module_prefix(state_dict):
"""
Removes the 'module.' prefix from each key in the state dictionary.
This is useful when loading a DataParallel model state into a non-DataParallel model.
"""
new_state_dict = {k.replace('module.', ''): v for k, v in state_dict.items()}
return new_state_dict
# Load your state dict with the 'module.' prefix
original_state_dict = torch.load('model_en.pkl')
updated_state_dict = remove_module_prefix(original_state_dict)
model_en.load_state_dict(updated_state_dict)
original_state_dict = torch.load('model_de.pkl')
updated_state_dict = remove_module_prefix(original_state_dict)
model_de.load_state_dict(updated_state_dict)
original_state_dict = torch.load('model_class.pkl')
updated_state_dict = remove_module_prefix(original_state_dict)
model_class.load_state_dict(updated_state_dict)
Please, can you advice what I might be doing wrong? I am trying to run the eval script, I changed the path to the saved weigths but I am getting this:
RuntimeError: Error(s) in loading state_dict for EncoderNet: Missing key(s) in state_dict: "conv.weight", "conv.bias", "bn.weight", "bn.bias", "bn.running_mean", "bn.running_var", "en_layer1.0.conv1.weight", "en_layer1.0.conv1.bias", "en_layer1.0.bn1.weight", "en_layer1.0.bn1.bias", "en_layer1.0.bn1.running_mean", "en_layer1.0.bn1.running_var", "en_layer1.0.conv2.weight", "en_layer1.0.conv2.bias", "en_layer1.0.bn2.weight", "en_layer1.0.bn2.bias", "en_layer1.0.bn2.running_mean", "en_layer1.0.bn2.running_var", "en_layer2.0.conv1.weight", "en_layer2.0.conv1.bias", "en_layer2.0.bn1.weight", "en_layer2.0.bn1.bias", "en_layer2.0.bn1.running_mean", "en_layer2.0.bn1.running_var", "en_layer2.0.conv2.weight", "en_layer2.0.conv2.bias", "en_layer2.0.bn2.weight", "en_layer2.0.bn2.bias", "en_layer2.0.bn2.running_mean", "en_layer2.0.bn2.running_var", "en_layer2.0.downsample.0.weight", "en_layer2.0.downsample.0.bias", "en_layer2.0.downsample.1.weight", "en_layer2.0.downsample.1.bias", "en_layer2.0.downsample.1.running_mean", "en_layer2.0.downsample.1.running_var", "en_layer3.0.conv1.weight", "en_layer3.0.conv1.bias", "en_layer3.0.bn1.weight", "en_layer3.0.bn1.bias", "en_layer3.0.bn1.running_mean", "en_layer3.0.bn1.running_var", "en_layer3.0.conv2.weight", "en_layer3.0.conv2.bias", "en_layer3.0.bn2.weight", "en_layer3.0.bn2.bias", "en_layer3.0.bn2.running_mean", "en_layer3.0.bn2.running_var", "en_layer3.0.downsample.0.weight", "en_layer3.0.downsample.0.bias", "en_layer3.0.downsample.1.weight", "en_layer3.0.downsample.1.bias", "en_layer3.0.downsample.1.running_mean", "en_layer3.0.downsample.1.running_var", "en_layer4.0.conv1.weight", "en_layer4.0.conv1.bias", "en_layer4.0.bn1.weight", "en_layer4.0.bn1.bias", "en_layer4.0.bn1.running_mean", "en_layer4.0.bn1.running_var", "en_layer4.0.conv2.weight", "en_layer4.0.conv2.bias", "en_layer4.0.bn2.weight", "en_layer4.0.bn2.bias", "en_layer4.0.bn2.running_mean", "en_layer4.0.bn2.running_var", "en_layer4.0.downsample.0.weight", "en_layer4.0.downsample.0.bias", "en_layer4.0.downsample.1.weight", "en_layer4.0.downsample.1.bias", "en_layer4.0.downsample.1.running_mean", "en_layer4.0.downsample.1.running_var", "en_layer5.0.conv1.weight", "en_layer5.0.conv1.bias", "en_layer5.0.bn1.weight", "en_layer5.0.bn1.bias", "en_layer5.0.bn1.running_mean", "en_layer5.0.bn1.running_var", "en_layer5.0.conv2.weight", "en_layer5.0.conv2.bias", "en_layer5.0.bn2.weight", "en_layer5.0.bn2.bias", "en_layer5.0.bn2.running_mean", "en_layer5.0.bn2.running_var", "en_layer5.0.downsample.0.weight", "en_layer5.0.downsample.0.bias", "en_layer5.0.downsample.1.weight", "en_layer5.0.downsample.1.bias", "en_layer5.0.downsample.1.running_mean", "en_layer5.0.downsample.1.running_var", "en_layer5.1.conv1.weight", "en_layer5.1.conv1.bias", "en_layer5.1.bn1.weight", "en_layer5.1.bn1.bias", "en_layer5.1.bn1.running_mean", "en_layer5.1.bn1.running_var", "en_layer5.1.conv2.weight", "en_layer5.1.conv2.bias", "en_layer5.1.bn2.weight", "en_layer5.1.bn2.bias", "en_layer5.1.bn2.running_mean", "en_layer5.1.bn2.running_var". Unexpected key(s) in state_dict: "module.conv.weight", "module.conv.bias", "module.bn.weight", "module.bn.bias", "module.bn.running_mean", "module.bn.running_var", "module.en_layer1.0.conv1.weight", "module.en_layer1.0.conv1.bias", "module.en_layer1.0.bn1.weight", "module.en_layer1.0.bn1.bias", "module.en_layer1.0.bn1.running_mean", "module.en_layer1.0.bn1.running_var", "module.en_layer1.0.conv2.weight", "module.en_layer1.0.conv2.bias", "module.en_layer1.0.bn2.weight", "module.en_layer1.0.bn2.bias", "module.en_layer1.0.bn2.running_mean", "module.en_layer1.0.bn2.running_var", "module.en_layer2.0.conv1.weight", "module.en_layer2.0.conv1.bias", "module.en_layer2.0.bn1.weight", "module.en_layer2.0.bn1.bias", "module.en_layer2.0.bn1.running_mean", "module.en_layer2.0.bn1.running_var", "module.en_layer2.0.conv2.weight", "module.en_layer2.0.conv2.bias", "module.en_layer2.0.bn2.weight", "module.en_layer2.0.bn2.bias", "module.en_layer2.0.bn2.running_mean", "module.en_layer2.0.bn2.running_var", "module.en_layer2.0.downsample.0.weight", "module.en_layer2.0.downsample.0.bias", "module.en_layer2.0.downsample.1.weight", "module.en_layer2.0.downsample.1.bias", "module.en_layer2.0.downsample.1.running_mean", "module.en_layer2.0.downsample.1.running_var", "module.en_layer3.0.conv1.weight", "module.en_layer3.0.conv1.bias", "module.en_layer3.0.bn1.weight", "module.en_layer3.0.bn1.bias", "module.en_layer3.0.bn1.running_mean", "module.en_layer3.0.bn1.running_var", "module.en_layer3.0.conv2.weight", "module.en_layer3.0.conv2.bias", "module.en_layer3.0.bn2.weight", "module.en_layer3.0.bn2.bias", "module.en_layer3.0.bn2.running_mean", "module.en_layer3.0.bn2.running_var", "module.en_layer3.0.downsample.0.weight", "module.en_layer3.0.downsample.0.bias", "module.en_layer3.0.downsample.1.weight", "module.en_layer3.0.downsample.1.bias", "module.en_layer3.0.downsample.1.running_mean", "module.en_layer3.0.downsample.1.running_var", "module.en_layer4.0.conv1.weight", "module.en_layer4.0.conv1.bias", "module.en_layer4.0.bn1.weight", "module.en_layer4.0.bn1.bias", "module.en_layer4.0.bn1.running_mean", "module.en_layer4.0.bn1.running_var", "module.en_layer4.0.conv2.weight", "module.en_layer4.0.conv2.bias", "module.en_layer4.0.bn2.weight", "module.en_layer4.0.bn2.bias", "module.en_layer4.0.bn2.running_mean", "module.en_layer4.0.bn2.running_var", "module.en_layer4.0.downsample.0.weight", "module.en_layer4.0.downsample.0.bias", "module.en_layer4.0.downsample.1.weight", "module.en_layer4.0.downsample.1.bias", "module.en_layer4.0.downsample.1.running_mean", "module.en_layer4.0.downsample.1.running_var", "module.en_layer5.0.conv1.weight", "module.en_layer5.0.conv1.bias", "module.en_layer5.0.bn1.weight", "module.en_layer5.0.bn1.bias", "module.en_layer5.0.bn1.running_mean", "module.en_layer5.0.bn1.running_var", "module.en_layer5.0.conv2.weight", "module.en_layer5.0.conv2.bias", "module.en_layer5.0.bn2.weight", "module.en_layer5.0.bn2.bias", "module.en_layer5.0.bn2.running_mean", "module.en_layer5.0.bn2.running_var", "module.en_layer5.0.downsample.0.weight", "module.en_layer5.0.downsample.0.bias", "module.en_layer5.0.downsample.1.weight", "module.en_layer5.0.downsample.1.bias", "module.en_layer5.0.downsample.1.running_mean", "module.en_layer5.0.downsample.1.running_var", "module.en_layer5.1.conv1.weight", "module.en_layer5.1.conv1.bias", "module.en_layer5.1.bn1.weight", "module.en_layer5.1.bn1.bias", "module.en_layer5.1.bn1.running_mean", "module.en_layer5.1.bn1.running_var", "module.en_layer5.1.conv2.weight", "module.en_layer5.1.conv2.bias", "module.en_layer5.1.bn2.weight", "module.en_layer5.1.bn2.bias", "module.en_layer5.1.bn2.running_mean", "module.en_layer5.1.bn2.running_var".