LoginSignup
20
12

More than 5 years have passed since last update.

速習!冬休みにfast.aiを勉強してインスタントAI技術者になる?

Last updated at Posted at 2018-12-20

冬休みの学習テーマ

会社の2018年12月アドベントカレンダー用に書きました。
昨今話題の人工知能。
冬休みに fast.ai を勉強してインスタントAI技術者になろう。

人工知能の勉強の仕方

  • 人工知能も民主化が進み、勉強する方法はたくさん。

-- むしろたくさんありすぎて目がくらくら。

無料コースウェア fast.ai

  • Jeremy Howardという元Kaggle Championが教えているオンラインコース
  • 機械学習や数学についての前提知識をほとんど必要とせず,ある程度コードがかける人向けにディープラーニングを教えるもの
  • Kaggleは機械学習のプロコンみたいなもので,世界中の猛者が賞金を求めて競い合う
  • 無料
  • 2時間で7コース(1コース10時間の学習を想定) : Practical Deep Learning For Codersの場合
  • トップダウンアプローチ(コードを書くところから始める)でニューラルネットワークの学習
  • Jupyter Notebookで演習
  • YouTubeでも無料でみられるがコースウェア視聴を推奨
  • 日本語の字幕付き!

fast.aiで最初にはまるところ

  • fast.aiは無料でビデオを見ながら勉強できます
  • 最初にはまるのはセットアップが古いこと 選択肢は次の通り

―― NVIDIA GPUボード付PC
―― GPUサーバレンタル
――― Crestle
――― Paperspace
- おいおい、Colaboratory じゃないのかよ。
- 大丈夫 Colaboratoryがあれば無料で学べます

Colaboratoryでfast.aiを学ぶ

読むのがめんどうくさい人のための日本語訳

  • 要するに毎回最初にこれを挿入する
!pip3 install fastai
  • レッスン1の犬猫データの取得
# Get the Dogs & Cats data, unzip it, and put it in the 'data' directory:
!wget http://files.fast.ai/data/dogscats.zip && unzip dogscats.zip -d data/

# Check to make sure the folders all unzipped properly:
!ls data/dogscats
  • レッスン3のデータの取得(無茶苦茶時間かかります。。)
# Get the Rossmann data and make a directory to put it in:
!wget http://files.fast.ai/part2/lesson14/rossmann.tgz && mkdir -p ~/data/rossmann

# Unzip the .tgz file, and put it in the right directory:
# x for extract
# -v for verbose    # NOTE: I usually turn this off; it prints a lot...
# -z for gnuzip
# -f for file (should come at last just before file name)
# -C to extract the zipped contents to a different directory
!tar -xzf rossmann.tgz -C ~/data/rossmann/

# Make sure the data is where we think it is:
!ls ~/data/rossmann

‐ レッスン4のデータの取得(試してません。。。)

# Get the IMDB data:
!wget http://files.fast.ai/data/aclImdb.tgz

# Unzip the tgz file, and put it in the right directory:
# x for extract
# -v for verbose    # NOTE: I usually turn this off; it prints a lot...
# -z for gnuzip
# -f for file (should come at last just before file name)
# -C to extract the zipped contents to a different directory
!tar -xvzf aclImdb.tgz -C data/

# Make sure the data is where we think it is:
!ls data/aclImdb
  • Kaggle CLIを使ったレッスン2のデータのKaggleからの取得(試してません。。。)
# Install the Kaggle API
!pip3 install kaggle

# Import kaggle.json from Google Drive
# This snippet will output a link which needs authentication from any Google account
from googleapiclient.discovery import build
import io, os
from googleapiclient.http import MediaIoBaseDownload
from google.colab import auth

auth.authenticate_user()

drive_service = build('drive', 'v3')
results = drive_service.files().list(
        q="name = 'kaggle.json'", fields="files(id)").execute()
kaggle_api_key = results.get('files', [])

filename = "/content/.kaggle/kaggle.json"
os.makedirs(os.path.dirname(filename), exist_ok=True)

request = drive_service.files().get_media(fileId=kaggle_api_key[0]['id'])
fh = io.FileIO(filename, 'wb')
downloader = MediaIoBaseDownload(fh, request)
done = False
while done is False:
    status, done = downloader.next_chunk()
    print("Download %d%%." % int(status.progress() * 100))
os.chmod(filename, 600)

# List the files for the Planet data 
!kaggle competitions files -c planet-understanding-the-amazon-from-space

# Download the data from Kaggle
# -c: competition name
# -f: which file you want to download
# -p: path to where the file should be saved
!kaggle competitions download -c planet-understanding-the-amazon-from-space -f train-jpg.tar.7z -p ~/data/planet/
!kaggle competitions download -c planet-understanding-the-amazon-from-space -f test-jpg.tar.7z -p ~/data/planet/
!kaggle competitions download -c planet-understanding-the-amazon-from-space -f train_v2.csv.zip -p ~/data/planet/

# In order to unzip the 7z files, need to install p7zip
# This was helpful: http://forums.fast.ai/t/unzipping-tar-7z-files-in-google-collab-notebook/14857/4
!apt-get install p7zip-full

# Unzip the 7zip files 
# -d: which file to un7zip
!p7zip -d ~/data/planet/test-jpg.tar.7z #-oc:/data/planet
!p7zip -d ~/data/planet/train-jpg.tar.7z #-oc:/data/planet

# Unzip the .tar files 
!tar -xvf ~/data/planet/test-jpg.tar
!tar -xvf ~/data/planet/train-jpg.tar

# Move the unzipped folders into data/planet/
!mv test-jpg ~/data/planet/ && mv train-jpg ~/data/planet/

# Unzip the regular file
!unzip ~/data/planet/train_v2.csv.zip -d ~/data/planet/

# Make sure everything looks as it should:
!ls ~/data/planet/

Colaboratoryの設定

‐ ちなみに言語はPython3、GPUは「あり」で使います
- Colaboratoryの使い方は Google Colabの知っておくべき使い方 – Google Colaboratoryのメリット・デメリットや基本操作のまとめ

おわりに:サルでもわかるディープラーニング

  • 人工知能の民主化といえば2016年に サルでもわかるディープラーニングを書きました
  • 私の理解では:
    -- 多段のニューラルネットワークがあればどんな学習も記述可能
    -- 深層学習はn次元方程式をn個の入力で近似解

  • 1980年代の発見が今ブームな理由
    -- 計算資源が豊富
    -- データが豊富
    -- 過学習を止める手法が進化

20
12
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
20
12