pytorch loads an already saved model file and uses it as a pretrained weight for another network
Problem Description
(For making notes by yourself) I saved the trained model before, and now I want to load the model in.
Solution
#加载保存好的模型
Layer1pre = torch.load('./ResultData_earlystop/savemodel/checkpoint_model_layer1.pt')
#定义自己的模型
model = CNNLayer(num_classes=10, aux_logits=True)
if use_gpu:
model = model.cuda()
#将模型权重更新到新的网络中
model.load_state_dict(Layer1pre, strict=False)
Reference link: https://blog.csdn.net/my_kingdom/article/details/85218478