2
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

google Colaboratoryで簡単にファイルの入出力

Last updated at Posted at 2019-04-14

ドライブ内にpngファイルを保存してみる

from google.colab import drive
drive.mount('./gdrive')

とすると

Go to this URL in a browser: ハイパーリンクがここに表示される

Enter your authorization code:
··········
□

ここでパスワードの入力を求められるので,上のハイパーリンクをクリックしてサイトに飛ぶ

アカウントの選択
「Google Drive File Stream」に移動

ここでcolaboratoryで保存したいgoogle driveのアカウント(私の場合はcolaboratoryで使用しているアカウント)をクリック

Google Drive File Stream が Google アカウントへのアクセスをリクエストしています

下の方を見ると「許可」のボタンがあるので,それを押す

ログイン

このコードをコピーし、アプリケーションに切り替えて貼り付けてください。

4/LAGqa4WWzSrti88D5C0P6kfYJbfL-XhnCTQmfp

のように長いパスワードが表示されるので,それをコピーして最初に求められたパスワードのところに張り付ける.

!ls gdrive

!と打つとlinuxコマンドが使えるので,マウントが成功したかを確認
成功していると

'My Drive'

と出力される.


drive_root_dir="./gdrive/My Drive"

import numpy as np
from PIL import Image

img = (np.random.rand(128,128,3)*255.0).astype(np.uint8)
print(img)
print(drive_root_dir+"/noise.png")
np.save(drive_root_dir+"/noise", img)

でpng画像が保存ができる.

同様に,この状態でloadもそのままできます.

load_img = np.load(drive_root_dir+"/noise.npy")
print(load_img)

とすればnpyで画像をロードできます.

2
4
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
2
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?