resnet152=models.resnet152(pretrained=True)
pretrained_dict=resnet152.state_dict()
model_dict=model.state_dict()
#将pretrained_dict里不属于model_dict的键去除掉
pretrained_dict={k:v for k,v in pretrained_dict.items() if k in model_dict}
#更新现有的model_dict
model_dict.update(pretrained_dict)
#加载真正需要的state_dict
model.load_state_dict(model_dict)