LoginSignup
1
8

More than 3 years have passed since last update.

Google Colaboratoryから学習済みモデルをGoogle Driveに保存する

Posted at

内容

タイトルの通りGoogle Colaboratoryで学習したモデルをGoogle Driveに保存する方法です。

環境

  • Google Colaboratory
  • PyTorch 1.4.0

コード

from google.colab import drive #インポート
drive.mount('/content/gdrive') #GoogleDriveのマウント

このコードで認証が表示されるので認証を行い、表示されたものをコピペします。
これでGoogleDriveへの接続が完了します。

model_save_name = 'filename.pth' # 保存ファイル名
path = F"/content/gdrive/My Drive/機械学習/{model_save_name}" # 保存先pathの設定
torch.save(model.state_dict(), path) # 保存

このコードでファイル名、保存先、実際の保存を行っています。

まとめ

ローカルに保存する際とは少し異なったのでつまづきましたが、学習済みモデルをGoogleDriveに保存することができました。
これで使い回すことができます!!

1
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
8