LoginSignup
170
183

More than 5 years have passed since last update.

Google Colabを導入

Last updated at Posted at 2018-03-30

Google Colab とは無料クラウドサービスである。そして、GPUを無料で使える jupyter notebooks です。
できること:
+ python スキル練習。
+ Keras TensorFlow PyTorch OpenCV などの有名な機械学習ライブラリを簡単に利用可能です。

一番気になるのは GPU の利用料金は 無料 でございます。

はじめに

新しいColab Notebookを作成しましょう

Right click > More > Colaboratory

img

皆大好きの無料GPUを設定

デフォルトではCPUので、GPUに交換しましょう
編集 》ノートブックの設定 》ハードウェアアクセラレータ 》GPU 》保存

pythonやってみましょう

コード用の入力欄にコード入力してみましょう

.pyファイルをインポートしたり実行したり

とりあえず、drive権限を設定します

!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}

driveと連携設定

# make new directory for sync
!mkdir -p drive

# sync with drive
!google-drive-ocamlfuse drive

ソースを置いていたフォルダーをワークプレイスに設定

import os
os.chdir('/path/to/workplace')

データロードしてみる

# import pandas library
import pandas as pd
# read the online file by the URL provides above, and assign it to variable "df"
path="https://archive.ics.uci.edu/ml/machine-learning-databases/autos/imports-85.data"

df = pd.read_csv(path,header=None)
print("Done")

# print 5 records
df.head()

よく使うコマンド

ライブラリインストール方法
基本のコマンド:!pip install xxx !apt-get install xxx

Keras

!pip install -q keras
import keras

PyTorch

!pip install -q http://download.pytorch.org/whl/cu75/torch-0.2.0.post3-cp27-cp27mu-manylinux1_x86_64.whl torchvision
import torch

mxnet

!apt install libnvrtc8.0
!pip install mxnet-cu80
import mxnet as mx

OpenCV

!apt-get -qq install -y libsm6 libxext6 && pip install -q -U opencv-python
import cv2

xgboost

!pip install -q xgboost==0.4a30
import xgboost

GraphViz

!apt-get -qq install -y graphviz && pip install -q pydot
import pydot

GPUチェック

import tensorflow as tf
tf.test.gpu_device_name()

GPUタイプチェック

from tensorflow.python.client import device_lib
device_lib.list_local_devices()

RAMチェック

!cat /proc/meminfo

CPU情報

!cat /proc/cpuinfo

参照

Google Colab Free GPU Tutorial – Deep Learning Turkey – Medium

170
183
1

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
170
183