在 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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章