8、PyTorch的state_dict、parameters、modules源码
Save and Load the ModelPyTorch models store the learned parameters in an internal state dictionary, called state_dict. These can be persisted via the torch.save method:model = models.vgg16(weights='IMAGENET1K_V1')
# 保存模型的参数、优化器状态、batch_nomalization、drop_out等等一系列的buffer变量
# model.state_dict() 只保留模型的权重
torch.save(model.state_dict(), 'model_weights.pth')
# 每个model都会包含一个state_dict()状态字典...