Pit depth study of model self-pytorch encountered an error loading

After saving a neural network model, when the model has been trained loaded error code is as follows:

model = model.load_state_dict(torch.load(path))

Run the following results appear:

Error(s) in loading state_dict for ResNet18

Here Insert Picture Description
Such a problem, it should be the version of the reason, this statement now seems the new version does not support the (specific reason if you have friends to know, correct me ha ...... welcome message)

Here the above code into the following manner:

model_dict = torch.load(root)
model_dict_clone = model_dict.copy()
for key, value in model_dict_clone.items():
    if key.endswith(('running_mean', 'running_var')):
        del model_dict[key]

model.load_state_dict(model_dict, False)

Another method is to add False parameters directly on the original code, as follows:

model.load_state_dict(torch.load(root),False)

White learning time is not long, welcome friends to exchange comments ......

Published 16 original articles · won praise 3 · Views 1084

Guess you like

Origin blog.csdn.net/weixin_42233120/article/details/100651735