覚え書きブログ

Deep Learning覚え書き(WindowsへのChainerのインストール)

前回、CUDA7.5をインストールしたWindowsに、chainerをインストールしてみた。
hirotaka-hachiya.hatenablog.com

環境としては、

  • Windows10 64bit + GTX980
  • CUDA Toolkit 7.5
  • Anaconda 2.4.1 (Python 2.7.11)

である。

とりあえず、pipでchainerをインストールしてみたが、次のようなエラーがでた。

C:\Users\PC User>pip install chainer
Collecting chainer
  Downloading chainer-1.9.1.tar.gz (966kB)
    100% |################################| 970kB 113kB/s
    Complete output from command python setup.py egg_info:
    running egg_info
    creating pip-egg-info\chainer.egg-info
    writing requirements to pip-egg-info\chainer.egg-info\requires.txt
    writing pip-egg-info\chainer.egg-info\PKG-INFO
    writing top-level names to pip-egg-info\chainer.egg-info\top_level.txt
    writing dependency_links to pip-egg-info\chainer.egg-info\dependency_links.txt
    writing manifest file 'pip-egg-info\chainer.egg-info\SOURCES.txt'
    warning: manifest_maker: standard file '-c' not found

    Executing cythonize
    Options: {'profile': False, 'annotate': False, 'linetrace': False, 'no_cuda': False}
    Include directories: ['C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v7.5\\include']
    Library directories: ['C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v7.5\\bin', 'C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v7.5\\lib\\x64']
    error: Microsoft Visual C++ 9.0 is required (Unable to find vcvarsall.bat). Get it from http://aka.ms/vcpython27

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in c:\users\pcuser~1\appdata\local\temp\pip-build-tdroxs\chainer
You are using pip version 7.1.2, however version 8.1.2 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

そこで、次の手順でchainerを再度インストールした。
1)Microsoft Visual C++ Compiler for Python 2.7をインストール
https://www.microsoft.com/en-us/download/details.aspx?id=44266

2)pipのアップグレード

C:\Users\PC User>python -m pip install --upgrade pip
Collecting pip
  Downloading pip-8.1.2-py2.py3-none-any.whl (1.2MB)
    100% |################################| 1.2MB 93kB/s
Installing collected packages: pip
  Found existing installation: pip 7.1.2
    Uninstalling pip-7.1.2:
      Successfully uninstalled pip-7.1.2
Successfully installed pip-8.1.2

3)もう一度pipでchainerをインストール

>pip install chainer
Collecting chainer
  Using cached chainer-1.9.1.tar.gz
Collecting filelock (from chainer)
  Downloading filelock-2.0.6.tar.gz
Requirement already satisfied (use --upgrade to upgrade): nose in c:\users\pc user\anaconda2\lib\site-packages (from chainer)
Requirement already satisfied (use --upgrade to upgrade): numpy>=1.9.0 in c:\users\pc user\anaconda2\lib\site-packages (from chainer)
Collecting protobuf (from chainer)
  Downloading protobuf-2.6.1.tar.gz (188kB)
    100% |################################| 194kB 553kB/s
Requirement already satisfied (use --upgrade to upgrade): six>=1.9.0 in c:\users\pc user\anaconda2\lib\site-packages (from chainer)
Requirement already satisfied (use --upgrade to upgrade): setuptools in c:\users\pc user\anaconda2\lib\site-packages\setuptools-18.5-py2.7.egg (from protobuf->chainer)
Building wheels for collected packages: chainer, filelock, protobuf
  Running setup.py bdist_wheel for chainer ... done
  Stored in directory: C:\Users\PC User\AppData\Local\pip\Cache\wheels\23\30\4d\1f02916e103b6073056d35ee081944c5b913bd3dbc16724cc9
  Running setup.py bdist_wheel for filelock ... done
  Stored in directory: C:\Users\PC User\AppData\Local\pip\Cache\wheels\97\9b\c0\47c42b4f38b378a65671364fb62ae7822b68b13f8048221d07
  Running setup.py bdist_wheel for protobuf ... done
  Stored in directory: C:\Users\PC User\AppData\Local\pip\Cache\wheels\c9\97\49\1bf6b7b58d0adec650bcb625b6656877437d1f7d18c32e88ee
Successfully built chainer filelock protobuf
Installing collected packages: filelock, protobuf, chainer
Successfully installed chainer-1.9.1 filelock-2.0.6 protobuf-2.6.1
C:\Users\PC User>python
Python 2.7.11 |Anaconda 2.4.1 (64-bit)| (default, Dec  7 2015, 14:10:42) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> import chainer

4)MNISTのサンプルを実行
GitHubからchainer-master.zipをダウンロードし、適当な場所に解凍する。
https://github.com/pfnet/chainer
そして、コマンドプロンプトで、解凍したフォルダに移動し、train_mnist.pyを実行する。

>cd "C:\Users\PC User\Documents\DeepLearning\chainer-master\examples\mnist"
>python train_mnist.py -g 0
GPU: 0
# 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
C:\Users\PC User\Anaconda2\lib\site-packages\chainer\cuda.py:85: UserWarning: cuDNN is not enabled.
Please reinstall chainer after you install cudnn
(see https://github.com/pfnet/chainer#installation).
  'cuDNN is not enabled.\n'
epoch 1
graph generated
train mean loss=0.188250914213, accuracy=0.943333335513, throughput=347.920883134 images/sec
test  mean loss=0.0980235926626, accuracy=0.968600001335
...
epoch 20
train mean loss=0.0102551415189, accuracy=0.997116669416, throughput=3565.06240475 images/sec
test  mean loss=0.109422553085, accuracy=0.98250000596
save the model
save the optimizer

次に、caffenetとalexnetの学習済みモデルとmeanファイルをダウンロードする。

> cd "C:\Users\PC User\Documents\DeepLearning\chainer-master\examples\modelzoo"
>python download_model.py caffenet
Downloading model file...
Done

> python download_model.py alexnet
Downloading model file...
Done

>python download_mean_file.py caffenet
Downloading ILSVRC12 mean file for NumPy...
Done

>dir
 ドライブ C のボリューム ラベルがありません。
 ボリューム シリアル番号は 203B-2677 です

 C:\Users\PC User\Documents\DeepLearning\chainer-master\examples\modelzoo のディレクトリ

2016/06/21  23:48    <DIR>          .
2016/06/21  23:48    <DIR>          ..
2016/06/16  22:04               106 .gitignore
2016/06/21  23:11       243,862,414 bvlc_alexnet.caffemodel
2016/06/21  23:14       243,862,418 bvlc_reference_caffenet.caffemodel
2016/06/16  22:04               305 download_mean_file.py
2016/06/16  22:04             1,358 download_model.py
2016/06/16  22:04             4,427 evaluate_caffe_net.py
2016/06/21  23:50         1,572,944 ilsvrc_2012_mean.npy
2016/06/16  22:04               554 README.md
               8 個のファイル         489,304,526 バイト