在 PyTorch 中保存训练模型的最佳方法? - Best way to save a trained model in PyTorch?

问题:

I was looking for alternative ways to save a trained model in PyTorch.我一直在寻找在 PyTorch 中保存训练模型的替代方法。 So far, I have found two alternatives.到目前为止,我找到了两种选择。

  1. torch.save() to save a model and torch.load() to load a model. torch.save()保存模型, torch.load()加载模型。
  2. model.state_dict() to save a trained model andmodel.load_state_dict() to load the saved model. model.state_dict()保存训练好的模型,model.load_state_dict()加载保存的模型。

I have come across to thisdiscussion where approach 2 is recommended over approach 1.我遇到过这个讨论,建议方法 2 优于方法 1。

My question is, why the second approach is preferred?我的问题是,为什么首选第二种方法? Is it only because torch.nn modules have those two function and we are encouraged to use them?仅仅是因为torch.nn模块具有这两个功能并且我们被鼓励使用它们吗?


解决方案:

参考一: https://en.stackoom.com/question/2tB88
参考二: https://stackoom.com/question/2tB88
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章