问题描述:加载预训练权重时报错Unexpected key(s) in state_dict: "model"
weight_dic_path = 'convnext_base_1k_224.pth'
state_dic=torch.load(weight_dic_path,map_location=device)
model.load_state_dict(state_dic)
解决方法:
weight_dic_path = 'convnext_base_1k_224.pth' state_dic=torch.load(weight_dic_path, map_location=device) new_state={} for k,v in state_dic.items(): #去除关键字”model" new_state=v for k,v in new_state.items(): print(k) model1.load_state_dict(new_state)
运行结果:
norm.bias
head.weight
head.bias
Process finished with exit code 0
完美运行