TensorflowとChainerのインストールの覚え書き
機械学習について興味があったので、とりあえずインストールしてサンプルを実行してみた。 インストール先は、Ubuntu 14.04 LTS (desktop版)。
事前準備
機械学習ではPythonが良く使われるらしく、pipを入れる。 あとPythonの実行環境を複数用意できるVirtualEnvを入れる。
sudo apt-get install python-pip python-dev python-virtualenv
Tensorflow
Download and Setup ・・・本家サイト
手順
VirtualEnvで用意した環境(~/tensorflow)に入れてみる。
virtualenv --system-site-packages ~/tensorflow source ~/tensorflow/bin/activate # 「source .../activate」は、~/.bash_aliasesに定義しておくと便利か。 # deactivateで元の環境に戻れる。
インストール (cpu onlyの場合)
pip install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.7.1-cp27-none-linux_x86_64.whl
テスト
hello.pyを作成して実行する。
import tensorflow as tf hello = tf.constant('Hello, TensorFlow!') sess = tf.Session() print sess.run(hello) a = tf.constant(10) b = tf.constant(32) print sess.run(a + b)
MNIST
python -m tensorflow.models.image.mnist.convolutional
非力なPC*1のVirtualBox上でやってみたら、約1日半かかってしまった。
Chainer
Install Guide — Chainer 1.8.0 documentation ・・・ 本家サイト
手順
VirtualEnvで用意した環境(~/chainer)に入れてみる。
virtualenv --system-site-packages ~/chainer source ~/chainer/bin/activate # 「source .../activate」は、~/.bash_aliasesに定義しておくと便利か。 # deactivateで元の環境に戻れる。
インストール (cpu onlyの場合)
sudo apt-get install g++ # インストール済みだった。 pip install -U setuptools # 最新だった pip install chainer
MNIST
gitが必要なので、apt-getで入れる。
sudo apt-get install git
とりあえず、chainter_test というディレクトリに落とした。
mkdir chainer_test cd chainer_test git clone https://github.com/pfnet/chainer.git
実行してみる。
python chainer/examples/mnist/train_mnist.py
Tensorflowで懲りたので、もっと速いPC*2のVirtualBox上で実行したが、 結局のところ1日強かかってしまった。
コメント
機械学習はちゃんとPCを用意するか、AWSのGPUインスタンスを使うしかないか。
NVIDIA GTX750 Ti が1万ちょっとで入手可能のようだ。
参考サイト
ディープラーニングの有名ライブラリ5種を最短距離で試す半日コース(TensorFlow, Chainer, Caffe, DeepDream, 画風変換) - Over&Out その後