Error while Loading trained weight

Hi, I transfer trained my original dataset after training FCHarDnet with CItyscapes data.

During loading the trained weight for inference, I met problem.

While transfer train FCHarDnet,
I inserted the layer to match the class number.
Like below

# While Training, I wrap HarDnet & layer with nn.Sequential
model = FCHarDnet.to(device) 
model = nn.Sequential(model,
                      nn.Conv2d(19, out_channels=11, kernel_size=1, stride=1,padding=0, bias=True)).to(device)

Then, I loaded trained weight like below,

# While inference
model = FCHarDnet.to(device) 
model = nn.Sequential(model,
                      nn.Conv2d(19, out_channels=11, kernel_size=1, stride=1,padding=0, bias=True)).to(device)
state = convert_state_dict(torch.load(args.model_path)["model_state"])
model.load_state_dict(state)

While

# convert_state_dict function

def convert_state_dict(state_dict):
    """Converts a state dict saved from a dataParallel module to normal
       module state_dict inplace
       :param state_dict is the loaded DataParallel model_state
    """
    new_state_dict = OrderedDict()
    for k, v in state_dict.items():
        name = k[7:]  # remove `module.`
        new_state_dict[name] = v
    return new_state_dict

And then met error like this…

Missing key(s) in state_dict: "0.base.0.conv.weight", "0.base.0.norm.weight", "0.base.0.norm.bias", "0.base.0.norm.running_mean",
     :
     :
     :
Unexpected key(s) in state_dict: "base.0.conv.weight", "base.0.norm.weight", "base.0.norm.bias", "base.0.norm.running_mean",
     :
     :
     :

I assume weight couldn’t be loaded because of key name didn’t match?
If that’s correct, will someone please share the code of how to fix this problem.

Thank you

Based on the error message it seems the state_dict might have been saved directly using the FCHarDnet model without wrapping it into an nn.Sequential container.
Could this be the case?

If so, you could add the mitssing 0. in front of the keys.
However, this would also mean that the parameters of the conv layer weren’t saved.

Thank you for your advice.

This time,

FCHarDnet model without wrapping it into an nn.Sequential container.
Could this be the case?

This was causing the problem.