pretrained-models.pytorch icon indicating copy to clipboard operation
pretrained-models.pytorch copied to clipboard

Xception pretrained state_dict keys no longer match the parameter names in the xception class

Open jiversivers opened this issue 1 year ago • 0 comments

For anyone in the same boat, this will fix it:

state_dict = torch.load(f'{torch.hub.get_dir()}\checkpoints\xception-43020ad28.pth')
state_dict['last_linear.weight'] = state_dict.pop('fc.weight')
state_dict['last_linear.bias'] = state_dict.pop('fc.bias')

And you can save the "new" model under the same name so you don't have to do this more than once with:

torch.save(state_dict, f'{torch.hub.get_dir()}/checkpoints/xception-43020ad28.pth')

jiversivers avatar May 31 '24 19:05 jiversivers