How to load load_state_dict for ResNet model

I have two models. ModelA and ModelB both are resnet50 model. I have pre-trained weights from modelA and they looks like.

|module.encoder.conv1.weight | torch.Size([64, 3, 7, 7])|
|module.encoder.bn1.weight | torch.Size([64])|
|module.encoder.bn1.bias | torch.Size([64])|
|module.encoder.bn1.running_mean | torch.Size([64])|
|module.encoder.bn1.running_var | torch.Size([64])|

However, when I define modelB it has model weight in

encoder.conv1.weight   torch.Size([64, 3, 7, 7])
encoder.bn1.weight   torch.Size([64])
encoder.bn1.bias   torch.Size([64])
encoder.bn1.running_mean   torch.Size([64])
encoder.bn1.running_var    torch.Size([64]). 

RuntimeError: Error(s) in loading state_dict for ResNetEncoder:
	Unexpected key(s) in state_dict: "module.encoder.conv1.weight", "module.encoder.bn1.weight", "module.encoder.bn1.bias", "module.encoder.bn1.running_mean", "module.encoder.bn1.running_var", "module.encoder.bn1.num_batches_tracked", 

I am trying to load modelA weights into modelB. However, I am getting error. Please help me.

# create new OrderedDict that does not contain `module.`
from collections import OrderedDict

# original saved file with DataParallel
ckpt = torch.load("pretraied_model.pth")
state_dict = ckpt['model']    # incase there are extra parameters in the model

new_state_dict = OrderedDict()

for k, v in state_dict.items():
    name =  k.replace("module.encoder.","encoder.")
    new_state_dict[name] = v

# load params

Thanks to post