LoginSignup
2
4

More than 5 years have passed since last update.

GoogleColaboratory で使う画像をGoogleドライブからコピー

Posted at

対象者

  • GoogleColaboratoryをこれから使う人
  • Googleドライブにある大量の画像をGoogleColaboratoryを使い深層学習させてい人

背景

  • GoogleColaboratoryで写真の分類をしたい。大量の画像はGoogleドライブ経由だといけるらしい
  • Googleドライブにある機械学習用の画像約1万枚をGoogleColaboratoryから直接参照すると、学習が進まない現象が起きた
  • GoogleドライブへのIOが極端に遅いことにあたりをつけGoogleColaboratoryのローカルへコピーすると問題なく学習が進んだ

Googleドライブマウント

# libray ダウンロード
!pip install -U -q PyDrive

from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
from google.colab import auth
from oauth2client.client import GoogleCredentials

# Google Drive API
auth.authenticate_user()
gauth = GoogleAuth()
gauth.credentials = GoogleCredentials.get_application_default()
drive = GoogleDrive(gauth)

apt-get install -y -qq software-properties-common python-software-properties module-init-tools
!add-apt-repository -y ppa:alessandro-strada/ppa 2>&1 > /dev/null
!apt-get update -qq 2>&1 > /dev/null
!apt-get -y install -qq google-drive-ocamlfuse fuse
from google.colab import auth
auth.authenticate_user()
from oauth2client.client import GoogleCredentials
creds = GoogleCredentials.get_application_default()
import getpass
!google-drive-ocamlfuse -headless -id={creds.client_id} -secret={creds.client_secret} < /dev/null 2>&1 | grep URL
vcode = getpass.getpass()
!echo {vcode} | google-drive-ocamlfuse -headless -id={creds.client_id} -secret={creds.client_secret}


### Googleドライブをマウント ###

!mkdir -p drive
!google-drive-ocamlfuse drive

ローカルへコピー

!mkdir -p /image/train
!mkdir -p /image/test
!rsync -av  --delete --progress drive/deep/train/ /image/train
!rsync -av  --delete --progress drive/deep/test/ /image/test
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