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.