Error loading resnet50-19c8e357.pth

Hi all!

I got an error like this

Traceback (most recent call last):
File “”, line 115, in
model = load_pretrain(model)
File “”, line 48, in load_pretrain
model_dict[k] = pretrained_dict[k[k.find(".") + 1:]]
KeyError: ‘bn1.num_batches_tracked’

when I tried to load a pre-trained ResNet model from pytorch “

My loading function for the pre-trained model is:
def load_pretrain(model):
url = ‘
pretrained_dict = model_zoo.load_url(url)
model_dict = model.state_dict()
for k, v in model_dict.items():
if not “cls_fc” in k:
model_dict[k] = pretrained_dict[k[k.find(".") + 1:]]
return model

Could anyone please to help me?

This is newly added, so it is in your new state_dict, but not in the downloaded one. We have code to handle this if you are just using load_state_dict on the downloaded one. However, since you are looking keys up in the old state_dict basing on the new state_dict, it won’t work. You could safely skip those.

Thank you Simon. I just noticed that I wrote my per-train code in 0.3.1 style, but run with 0.4.1.