【发布时间】:2021-06-23 12:59:46
【问题描述】:
我是深度学习的新手,我想知道如何在 Pytorch 中保存最终模型?我尝试了一些提到的东西,但我对如何保存模型以及如何加载它感到困惑?
【问题讨论】:
-
请注意,Pytorch 问题应被标记为此类(已编辑)。
-
这能回答你的问题吗? Best way to save a trained model in PyTorch?
标签: pytorch
我是深度学习的新手,我想知道如何在 Pytorch 中保存最终模型?我尝试了一些提到的东西,但我对如何保存模型以及如何加载它感到困惑?
【问题讨论】:
标签: pytorch
保存:
# save the weights of the model to a .pt file
torch.save(model.state_dict(), "your_model_path.pt")
加载:
# load your model architecture/module
model = YourModel()
# fill your architecture with the trained weights
model.load_state_dict(torch.load("your_model_path.pt"))
【讨论】: