2016年6月22日水曜日

とりあえずChainerをインストールしてみる

で、とりあえずChainerをインストールしてみる。

Chainerをインストールするために、chainer.orgに行く。
インストール方法は簡単で、Pythonをインストール済みの環境ならば、次のコマンドを打つだけ。

$ pip install chainer

テスト用サンプルがあるらしいので、これから始めてみよう。

$ wget https://github.com/pfnet/chainer/archive/v1.9.1.tar.gz
$ tar xzf v1.9.1.tar.gz
$ python chainer-1.9.1/examples/mnist/train_mnist.py

実行してみようとしたら、wgetがないという。
$ which wget

反応なしなので、やっぱりインストールはされていない。

では次のコマンドでwgetをインストールする。

$ brew install wget
==> Downloading https://homebrew.bintray.com/bottles/wget-1.18.el_capitan.bottle
######################################################################## 100.0%
==> Pouring wget-1.18.el_capitan.bottle.tar.gz
🍺  /usr/local/Cellar/wget/1.18: 9 files, 1.6M

パッケージ管理システムは、ほんと便利、ありがたい。
気を取り直して、再挑戦。

$ wget https://github.com/pfnet/chainer/archive/v1.9.1.tar.gz
--2016-06-22 20:44:26--  https://github.com/pfnet/chainer/archive/v1.9.1.tar.gz
Resolving github.com... 192.30.252.122
Connecting to github.com|192.30.252.122|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://codeload.github.com/pfnet/chainer/tar.gz/v1.9.1 [following]
--2016-06-22 20:44:27--  https://codeload.github.com/pfnet/chainer/tar.gz/v1.9.1
Resolving codeload.github.com... 192.30.253.120
Connecting to codeload.github.com|192.30.253.120|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [application/x-gzip]
Saving to: ‘v1.9.1.tar.gz’

v1.9.1.tar.gz           [             <=>    ]   1.80M   622KB/s    in 3.0s

2016-06-22 20:44:31 (622 KB/s) - ‘v1.9.1.tar.gz’ saved [1893254]

ダウンロードが済んだら、圧縮ファイルを展開。
$ tar xzf v1.9.1.tar.gz

で実行してみる。
$ python3 chainer-1.9.1/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.19060514808942874, accuracy=0.9417666694770257, throughput=4271.602999064454 images/sec
test  mean loss=0.087592640517978, accuracy=0.9728000050783158
epoch 2
train mean loss=0.0738531613512896, accuracy=0.9769333433111509, throughput=3953.7409389202767 images/sec
test  mean loss=0.07370956073747947, accuracy=0.9775000071525574
epoch 3
train mean loss=0.04970679437314781, accuracy=0.9846500095725059, throughput=3811.6873914039775 images/sec
test  mean loss=0.0637695388092834, accuracy=0.9800000065565109
epoch 4
train mean loss=0.03488761224221283, accuracy=0.9886000087857246, throughput=3692.2595329471765 images/sec
test  mean loss=0.07119732037186623, accuracy=0.9786000061035156
epoch 5
train mean loss=0.028896143916257035, accuracy=0.9905666745702426, throughput=3695.4207240808023 images/sec
test  mean loss=0.07256504680110083, accuracy=0.9788000077009201
epoch 6
train mean loss=0.02374378211319102, accuracy=0.9921833403905232, throughput=3583.3320328487594 images/sec
test  mean loss=0.10043191654083784, accuracy=0.9744000059366226
epoch 7
train mean loss=0.020924357878029695, accuracy=0.992866672972838, throughput=3592.6140728613955 images/sec
test  mean loss=0.06807603047812108, accuracy=0.9835000067949295
epoch 8
train mean loss=0.017630842202852364, accuracy=0.9942500052849451, throughput=3537.208209028512 images/sec
test  mean loss=0.08859721799534782, accuracy=0.9785000056028366
epoch 9
train mean loss=0.018209161819856188, accuracy=0.9943000053366026, throughput=3460.3185817121116 images/sec
test  mean loss=0.08362272959568146, accuracy=0.980100005865097
epoch 10
train mean loss=0.013510788094675567, accuracy=0.9956166708469391, throughput=3414.213791867741 images/sec
test  mean loss=0.09247089847276073, accuracy=0.9814000064134598
epoch 11
train mean loss=0.013009410188321151, accuracy=0.9958500039577484, throughput=3326.4933053556624 images/sec
test  mean loss=0.09212554091344487, accuracy=0.9791000074148178
epoch 12
train mean loss=0.013966237730543677, accuracy=0.9955333373943964, throughput=3213.203793557963 images/sec
test  mean loss=0.07512530633225424, accuracy=0.9832000082731247
epoch 13
train mean loss=0.011328027055885741, accuracy=0.9966166697939237, throughput=3143.6668155565453 images/sec
test  mean loss=0.11614390091075905, accuracy=0.9787000072002411
epoch 14
train mean loss=0.011522313533887427, accuracy=0.9965333365400633, throughput=3069.061238992809 images/sec
test  mean loss=0.10542018069097821, accuracy=0.9778000056743622
epoch 15
train mean loss=0.014500913300751487, accuracy=0.9957000040014585, throughput=2994.8600530405492 images/sec
test  mean loss=0.10059675336371895, accuracy=0.9800000071525574
epoch 16
train mean loss=0.0079077750227475, accuracy=0.9975333355863889, throughput=2914.1439322729966 images/sec
test  mean loss=0.08044841805511829, accuracy=0.9852000093460083
epoch 17
train mean loss=0.006486849701715869, accuracy=0.9980333352088928, throughput=2828.4838384387863 images/sec
test  mean loss=0.10793283259050049, accuracy=0.9788000065088273
epoch 18
train mean loss=0.0125344805511196, accuracy=0.9963000035285949, throughput=2795.0638334358655 images/sec
test  mean loss=0.10538647441120699, accuracy=0.9828000074625015
epoch 19
train mean loss=0.009864346119461895, accuracy=0.9970833361148834, throughput=2750.219816402364 images/sec
test  mean loss=0.12158339534574539, accuracy=0.9794000047445297
epoch 20
train mean loss=0.012885340018372063, accuracy=0.9962166701753934, throughput=2738.190540420163 images/sec
test  mean loss=0.0986378959132702, accuracy=0.982900008559227
save the model
save the optimizer

初期設定では、GPUは使用しないモードになっているらしい。
稼働中はメモリ使用量はあまり変化ないけれど、CPU負荷率は100%近い状態になっていた。

GPUを稼働させてみたいなあ。。。

0 件のコメント:

コメントを投稿