KeyError: 'unexpected key "module.densenet121.features.denseblock1.denselayer1.norm.1.weight" in state_dict

I am using the generic saved model DenseNet121 (file name: model.pth.tar).

While loading the above model I am getting the following error:

KeyError: ‘unexpected key “module.densenet121.features.denseblock1.denselayer1.norm.1.weight” in state_dict’

Complete Error:
model.load_state_dict(checkpoint[‘state_dict’])
File “/usr/local/lib/python3.6/site-packages/torch/nn/modules/module.py”, line 522, in load_state_dict
.format(name))
KeyError: ‘unexpected key “module.densenet121.features.denseblock1.denselayer1.norm.1.weight” in state_dict’

The loading part of the code:
CODE:
CKPT_PATH = ‘model.pth.tar’

cudnn.benchmark = True

model = DenseNet121(N_CLASSES).cuda()
model = torch.nn.DataParallel(model).cuda()

if os.path.isfile(CKPT_PATH):
    print("Loading checkpoint...")
    checkpoint = torch.load(CKPT_PATH)
    model.load_state_dict(checkpoint['state_dict'])
    print("Checkpoint Loaded Successfully.")
else:
    print("Checkpoint Not found.")

NOTE: I’ve tried to remove the ‘module.’ suggestion from another thread but did not help.

Please suggest.

I guess you should try to rename the variable model as densenet121. As far as I can see if the state dict contains module.childrens it should say module.model.childrens instead of module.densenet121

This indicates they called the variable densenet121