のねのBlog

パソコンの問題や、ソフトウェアの開発で起きた問題など書いていきます。よろしくお願いします^^。

fast.aiをgoogle colabで実行する方法

Python3のGPUありの設定で動作した。

共有ファイルを参照する方法を利用させてもらった。
qiita.com

!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
auth.authenticate_user()
gauth = GoogleAuth()
gauth.credentials = GoogleCredentials.get_application_default()
drive = GoogleDrive(gauth)

共有ファイルへのリンクをコピーする。
githubからfastaiをzipでダウンロードした。

#https://drive.google.com/open?id=1234567890123456789
id = '1234567890123456789'  # 共有リンクで取得した id= より後の部分
downloaded = drive.CreateFile({'id': id})
downloaded.GetContentFile('fastai.zip')
!unzip -o -qq fastai.zip

カレントディレクトリから、fastai-master>courses>dl1へ移動する

%cd ~
%pwd
%cd fastai-master
#!ls
%cd courses
#!ls
%cd dl1
!ls

catsdogs.zipを同様に共有ファイルからコピーしてきた。
fastai-master>courses>dl1>dataの中へコピーして、unzipした。

%cd ~
%pwd
%cd fastai-master
%cd courses
%cd dl1
!mkdir data
%cd data
%pwd

#https://drive.google.com/open?id=ABCDEFGHABCDEFGH
id2="ABCDEFGHABCDEFGH"# 共有リンクで取得した id= より後の部分
downloaded = drive.CreateFile({'id': id2})
downloaded.GetContentFile('dogscats.zip')

!unzip -o -qq dogscats.zip
!ls
%cd ..
!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