Google ColabでGUPを無料で使ってfast.aiの設定をする

fastaiというGoogleのJeremyさんの講義が無料で、しかも0から教えてくれるという学習にはもってこいの教材がある。ドキュメントもしっかりしてるし、動画もわかりやすい。しかし、一点だけ問題があるとすれば、GUP(サーバー)代が高いのだ。これはしょうがない。しかし、GoogleのColabはGPUがなんと無料で使えるという。オープンソースは最高です。

つまずくのが、ColabにFastaiをマウントするのに何時間かかかったので、そこの紹介を。詳細は、Gitを見てください。

Colabの設定

* ランタイム->ランタイプのタイプの変更->GPUにチェックしてから、実行

# Security by Google Colab
!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}

・マウントする

%%bash
mkdir -p drive
google-drive-ocamlfuse drive

・fastaiをアップロードして、受講したいLessonに移動

%%bash
cd
cd drive
cd fastai
cd courses
cd dl1
cd data
pwd

・Pytorchの使い方

!pip3 install http://download.pytorch.org/whl/cu80/torch-0.3.0.post4-cp36-cp36m-linux_x86_64.whl
!pip3 install torchvision
!pip install torchtext

!pip install bcolz
!pip install graphviz
!pip install sklearn_pandas
!pip install isoweek
!pip install pandas_summary
!pip install ipywidgets

・fastaiライブラリを実行してエラーが出なければOK

!pip install fastai
# This file contains all the main external libs we'll use
from fastai.imports import *
from fastai.transforms import *
from fastai.conv_learner import *
from fastai.model import *
from fastai.dataset import *
from fastai.sgdr import *
from fastai.plots import *

以上、Colabを使って無料でFastaiを受講する方法でした。

以前に、Fastaiの講義内容もメモしたものがあります。どんな内容かみたい人はこちらも。


この記事が気に入ったらサポートをしてみませんか?