2
3

More than 5 years have passed since last update.

Oracle CloudにChainerをインストールしてみる。

Last updated at Posted at 2016-05-17

Oracle Cloudには剥き身のOSだけが扱えるIaaSもありますが、PaaSであってもOSレイヤもいろいろいじれてしまえるのが特徴です。今回はPaaSの中のOracle Database Cloud Serviceにディープラーニングフレームワークで有名なChainerをインストールしてみます。

公式インストールガイド

Oracle Database Cloud Serviceの特徴としては、OSはOracle Linuxで固定となります。元々PaaSなので、OSを選択するという概念はありません。Oracle LinuxはRedhat互換のOSのため、パッケージのインストールにはyumを使用します。
あとは、OSユーザが最初から二つ作成されており、database管理系はなじみのoracleユーザですが、OS管理にはopcユーザが存在します。opcユーザはsudoが使えるので、root権限が必要な操作も実施することができます。今回は特にDatabaseと接続などは考えていないので、opcユーザを使用していきます。

Chainerを入れるための事前準備

個人的にpython使う時はpyenvでバージョンを管理したいので、pyenvをgit cloneで入れます。

[opc@OracleML ~]$ git clone https://github.com/yyuu/pyenv.git ~/.pyenv

bashrcに以下を追加

export PYENV_ROOT=\$HOME/.pyenv 
export PATH=\$PYENV_ROOT/bin:\$PATH
eval "\$(pyenv init -)"

書き終えたらbashrcを再読み込みすることによって、pyenvを使えるようにします。再ログインしてももちろん大丈夫です。

pyenvから最新のpython2.7をインストール(2016年5月17日時点)
※chainerは2.7.6+, 3.4.3+, 3.5.1+をサポートするので、python3系でももちろん動作します。

[opc@OracleML ~]$ pyenv install 2.7.11
Downloading Python-2.7.11.tgz...
-> https://www.python.org/ftp/python/2.7.11/Python-2.7.11.tgz
Installing Python-2.7.11...

インストールされているか確認

[opc@OracleML ~]$ pyenv versions
* system (set by /home/opc/.pyenv/version)
  2.7.11

※がついているのが現時点のバージョン。2.7.11を使いたいので、使うバージョンを変更します。

[opc@OracleML ~]$ pyenv global 2.7.11

改めて、バージョンの確認

[opc@OracleML ~]$ pyenv versions
  system
* 2.7.11 (set by /home/opc/.pyenv/version)

※が2.7.11についたのでこれで問題なし。

Chainer側のインストールにC++コンパイラが必要なので、インストールします。

[opc@OracleML ~]$ sudo yum install gcc-c++
※出力は長いので一部省略
Updated:
  gcc-c++.x86_64 0:4.4.7-16.el6

Dependency Updated:
  cpp.x86_64 0:4.4.7-16.el6               gcc.x86_64 0:4.4.7-16.el6
  gcc-gfortran.x86_64 0:4.4.7-16.el6      gcc-gnat.x86_64 0:4.4.7-16.el6
  gcc-java.x86_64 0:4.4.7-16.el6          gcc-objc.x86_64 0:4.4.7-16.el6
  gcc-objc++.x86_64 0:4.4.7-16.el6        libgcc.i686 0:4.4.7-16.el6
  libgcc.x86_64 0:4.4.7-16.el6            libgcj.x86_64 0:4.4.7-16.el6
  libgcj-devel.x86_64 0:4.4.7-16.el6      libgfortran.x86_64 0:4.4.7-16.el6
  libgnat.x86_64 0:4.4.7-16.el6           libgnat-devel.x86_64 0:4.4.7-16.el6
  libgomp.x86_64 0:4.4.7-16.el6           libobjc.x86_64 0:4.4.7-16.el6
  libstdc++.i686 0:4.4.7-16.el6           libstdc++.x86_64 0:4.4.7-16.el6
  libstdc++-devel.x86_64 0:4.4.7-16.el6

setuptoolsをアップグレードしておきます。

[opc@OracleML ~]$ pip install -U setuptools
Collecting setuptools
  Downloading setuptools-21.0.0-py2.py3-none-any.whl (509kB)
    100% |████████████████████████████████| 512kB 833kB/s
Installing collected packages: setuptools
  Found existing installation: setuptools 18.2
    Uninstalling setuptools-18.2:
      Successfully uninstalled setuptools-18.2
Successfully installed setuptools-21.0.0

Chainerのインストール

とは言ってもpipからchainerをインストールするだけです。

[opc@OracleML ~]$ pip install chainer
Collecting chainer
  Downloading chainer-1.8.2.tar.gz (934kB)
    100% |████████████████████████████████| 937kB 447kB/s
Collecting filelock (from chainer)
  Downloading filelock-2.0.6.tar.gz
Collecting nose (from chainer)
  Downloading nose-1.3.7-py2-none-any.whl (154kB)
    100% |████████████████████████████████| 155kB 2.7MB/s
Collecting numpy>=1.9.0 (from chainer)
  Downloading numpy-1.11.0.tar.gz (4.2MB)
    100% |████████████████████████████████| 4.2MB 111kB/s
Collecting protobuf (from chainer)
  Downloading protobuf-2.6.1.tar.gz (188kB)
    100% |████████████████████████████████| 188kB 1.8MB/s
Collecting six>=1.9.0 (from chainer)
  Downloading six-1.10.0-py2.py3-none-any.whl
Requirement already satisfied (use --upgrade to upgrade): setuptools in ./.pyenv/versions/2.7.11/lib/python2.7/site-packages (from protobuf->chainer)
Installing collected packages: filelock, nose, numpy, protobuf, six, chainer
  Running setup.py install for filelock
  Running setup.py install for numpy
  Running setup.py install for protobuf
  Running setup.py install for chainer
Successfully installed chainer-1.8.2 filelock-2.0.6 nose-1.3.7 numpy-1.11.0 protobuf-2.6.1 six-1.10.0

Chainerをインストールするとpythonの数値計算用ライブラリで有名なnumpyとかも合わせてインストールされます。

ちゃんと動くか確認

無事に動くか確かめるためにmnistのサンプルプログラムを実行
ファイルをダウンロードしてくるので作業用ディレクトリを作ります。
※圧縮状態で1.8MB弱のデータがダウンロードされます。

[opc@OracleML chainer]$ mkdir -p work/chainer
[opc@OracleML chainer]$ cd work/chainer
[opc@OracleML chainer]$ wget https://github.com/pfnet/chainer/archive/v1.8.2.tar.gz
--2016-05-17 15:23:18--  https://github.com/pfnet/chainer/archive/v1.8.2.tar.gz
Resolving github.com... 192.30.252.121
Connecting to github.com|192.30.252.121|:443... connected.
HTTP request sent, awaiting response... s/mnist/train_mnist.py302 Found
Location: https://codeload.github.com/pfnet/chainer/tar.gz/v1.8.2 [following]
--2016-05-17 15:23:19--  https://codeload.github.com/pfnet/chainer/tar.gz/v1.8.2
Resolving codeload.github.com... 192.30.252.144
Connecting to codeload.github.com|192.30.252.144|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [application/x-gzip]
Saving to: “v1.8.2.tar.gz”

    [     <=>                               ] 1,865,695   1.78M/s   in 1.0s

2016-05-17 15:23:21 (1.78 MB/s) - “v1.8.2.tar.gz” saved [1865695]

[opc@OracleML chainer]$ tar xzf v1.8.2.tar.gz
[opc@OracleML chainer]$ python chainer-1.8.2/examples/mnist/train_mnist.py
GPU: -1
# unit: 1000
# Minibatch-size: 100
# epoch: 20
Network type: simple

load MNIST dataset
Downloading train-images-idx3-ubyte.gz...
Done
Downloading train-labels-idx1-ubyte.gz...
Done
Downloading t10k-images-idx3-ubyte.gz...
Done
Downloading t10k-labels-idx1-ubyte.gz...
Done
Converting training data...
Done
Converting test data...
Done
Save output...
Done
Convert completed
epoch 1
graph generated
train mean loss=0.191361587822, accuracy=0.942716671055, throughput=41.6892000542 images/sec
test  mean loss=0.0909628344493, accuracy=0.969800004363
epoch 2
train mean loss=0.0739348402239, accuracy=0.977466677626, throughput=41.7980654511 images/sec
test  mean loss=0.0737590348307, accuracy=0.977700006962
epoch 3
train mean loss=0.0460491577055, accuracy=0.985283343196, throughput=41.8672285113 images/sec
test  mean loss=0.0851957379319, accuracy=0.972600005269
epoch 4
train mean loss=0.0372030753359, accuracy=0.988516676029, throughput=41.8309492376 images/sec
test  mean loss=0.0761305289133, accuracy=0.977800009251
epoch 5
train mean loss=0.0300519610067, accuracy=0.99026667436, throughput=41.8231355797 images/sec
test  mean loss=0.0759965585483, accuracy=0.979400006533
epoch 6
train mean loss=0.0228657945233, accuracy=0.992600006262, throughput=41.8207654705 images/sec
test  mean loss=0.07971162725, accuracy=0.978800007105
epoch 7
train mean loss=0.0186917934164, accuracy=0.994066672126, throughput=41.8575257029 images/sec
test  mean loss=0.0735157749392, accuracy=0.980700005293
epoch 8
train mean loss=0.0197259162495, accuracy=0.993233339489, throughput=41.8038634911 images/sec
test  mean loss=0.0788154986306, accuracy=0.981200004816
epoch 9
train mean loss=0.0186268132607, accuracy=0.994200005432, throughput=41.8321415426 images/sec
test  mean loss=0.0705992765316, accuracy=0.981400005817
epoch 10
train mean loss=0.0122995013625, accuracy=0.995800003906, throughput=41.8293981004 images/sec
test  mean loss=0.0840267806896, accuracy=0.980400006771
epoch 11
train mean loss=0.0152960172197, accuracy=0.994950004816, throughput=41.8024463269 images/sec
test  mean loss=0.0897405684877, accuracy=0.981700005531
epoch 12
train mean loss=0.011390889745, accuracy=0.996050003767, throughput=41.8014272636 images/sec
test  mean loss=0.0988696553496, accuracy=0.981500008106
epoch 13
train mean loss=0.0108807976301, accuracy=0.99655000329, throughput=41.7682246509 images/sec
test  mean loss=0.10508250903, accuracy=0.980000008345


2時間くらい回し続けて、epoch5までしか行きませんでした。
そのままサンプルスクリプトをキックすると1コアだけ100%で使い切る感じです。

推奨されるChainerのプラットフォームは

  • Ubuntu 14.04 LTS 64bit
  • CentOS 7 64bit

となっていますが、Oracle Linux(OL6.6)にも問題なくインストールすることができました。
次回はもう少しChainerで遊ぶか、Oracle Cloudとの連係らしいのを作っていきたいですね。

2
3
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
2
3