LoginSignup
7
5

More than 5 years have passed since last update.

Chainerを1.5にアップグレードするのにやったこと

Last updated at Posted at 2015-11-27

Chainerが先日v1.5になりました。
こちらにも書かれていますが、依存関係などが変わっているので、少しアップグレードにつまづいたので、主にHDF5関連でやったことを記述しておきます。

Chainer 1.5のインストールがうまくいかない人への非公式なTips

Ubuntuの場合

手元のローカル環境のものです。
これだけでした。

$ sudo apt-get install libhdf5-dev
$ sudo pip install --upgrade chainer

Amazon Linuxの場合

こちらを参考にAWSで立ち上げているインスタンスのものです。

$sudo yum install hdf5

でHDF5をインストールしようと試みたのですが、

$ sudo yum install hdf5
読み込んだプラグイン:dkms-build-requires, priorities, update-motd, upgrade-helper
amzn-graphics/latest                                     | 2.1 kB     00:00     
amzn-main/latest                                         | 2.1 kB     00:00     
amzn-updates/latest                                      | 2.3 kB     00:00     
2 packages excluded due to repository priority protections
パッケージ hdf5 は利用できません。
エラー: 何もしません

こんなエラーが出て、インストールできません。
どうやらパッケージに優先度が設定されており、特定のパッケージがHDF5のものより高く設定されており、できない模様です。こちらに変更の方法等が書いてありましたが、優先度を変更して他に影響があると困るので、怖くてできません。

CentOS yum メッセージ packages excluded due to repository priority protections

そこで、ソースから取ってきてビルドします。

こちらからlinux用のソースを取ってきます。

$ wget http://www.hdfgroup.org/ftp/HDF5/current/src/hdf5-1.8.16.tar
$ tar xvf hdf5-1.8.16.tar
$ cd hdf5-1.8.16.tar
$ ./configure --prefix=/usr/local/hdf5 --enable-fortran --enable-cxx
$ make -j8
$ make -j8 check
$ sudo make install
$ sudo make check-install

.bash_profileに環境変数を記述

.bash_profile
export HDF5_DIR=/usr/local/hdf5

この状態でchainerアップグレード

$ pip install --user --upgrade chainer

これでなんとかアップグレード成功しました。

しかしimagenetの実行でこんなエラーが

Traceback (most recent call last):
  File "./train_imagenet.py", line 317, in <module>
    train_loop()
  File "./train_imagenet.py", line 286, in train_loop
    serializers.save_hdf5(args.out, model)
  File "/home/ec2-user/.local/lib/python2.7/site-packages/chainer/serializers/hdf5.py", line 61, in save_hdf5
    s.save(obj)
  File "/home/ec2-user/.local/lib/python2.7/site-packages/chainer/serializer.py", line 64, in save
    obj.serialize(self)
  File "/home/ec2-user/.local/lib/python2.7/site-packages/chainer/link.py", line 546, in serialize
    d[name].serialize(serializer[name])
  File "/home/ec2-user/.local/lib/python2.7/site-packages/chainer/link.py", line 691, in serialize
    child.serialize(serializer['%d' % idx])
  File "/home/ec2-user/.local/lib/python2.7/site-packages/chainer/link.py", line 345, in serialize
    serializer(name, d[name].data)
  File "/home/ec2-user/.local/lib/python2.7/site-packages/chainer/serializers/hdf5.py", line 41, in __call__
    self.group.create_dataset(key, data=arr, compression=compression)
  File "/home/ec2-user/.local/lib/python2.7/site-packages/h5py/_hl/group.py", line 103, in create_dataset
    dsid = dataset.make_new_dset(self, shape, dtype, data, **kwds)
  File "/home/ec2-user/.local/lib/python2.7/site-packages/h5py/_hl/dataset.py", line 107, in make_new_dset
    shuffle, fletcher32, maxshape, scaleoffset)
  File "/home/ec2-user/.local/lib/python2.7/site-packages/h5py/_hl/filters.py", line 109, in generate_dcpl
    raise ValueError('Compression filter "%s" is unavailable' % compression)
ValueError: Compression filter "gzip" is unavailable

なんかgzipで圧縮しようとして、gzipのフィルターが見当たらないと言われる。
いろいろ調べたところ、HDF5のインストールマニュアルのzlibのところに

    The HDF5 Library includes a predefined compression filter that 
    uses the "deflate" method for chunked datasets. If zlib-1.1.2 or
    later is found, HDF5 will use it.  Otherwise, HDF5's predefined
    compression method will degenerate to a no-op; the compression
    filter will succeed but the data will not be compressed.  

とあった。簡単に訳せば、zlibが入ってないと、ビルド時はいいけど圧縮のときに失敗するよ、みたいなことが書いてある。入ってるはずだけど、一応確認。
こちらに確認の方法が書いてあったので、やってみる。

$ yum list installed|grep zlib
zlib.x86_64 ...

ある。だけれど、先のページの結果には、

$ yum list installed|grep zlib
zlib.x86_64 1.2.3-29.el6 @base
zlib-devel.x86_64 1.2.3-29.el6 @base

と、zlibのdevパッケージの存在が確認される。これが必要なんじゃないかと思い、インストール、HDF5とchainerをアンインストール後に再インストール

$ sudo yum install zlib-devel
$ sudo make uninstall
$ pip uninstall chainer
# 以下先ほどのHDF5インストール手順とchainerインストール

これでようやく、学習中にコケることがなくなった。

参考

HDF5公式
HDF5 Download and Installation
【centOS】zlibをインストールする方法

7
5
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
7
5