4/17にChainer 4.0.0がリリースされましたが、Anaconda3 4.2.0では以下のエラーがでて動かなくなっていました。
>>> import chainer
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Anaconda3\lib\site-packages\chainer\__init__.py", line 28, in <module>
from chainer import training # NOQA
File "C:\Anaconda3\lib\site-packages\chainer\training\__init__.py", line 2, in <module>
from chainer.training import extensions # NOQA
File "C:\Anaconda3\lib\site-packages\chainer\training\extensions\__init__.py", line 30, in <module>
from chainer.training.extensions.variable_statistics_plot import VariableStatisticsPlot # NOQA
File "C:\Anaconda3\lib\site-packages\chainer\training\extensions\variable_statistics_plot.py", line 16, in <module>
_plot_color = matplotlib.colors.to_rgba('#1f77b4') # C0 color
AttributeError: module 'matplotlib.colors' has no attribute 'to_rgba'
原因は、chainerがmatplotlibのバージョン2系を前提にしているためです。
Anaconda3 4.2.0のmatplotlibのバージョンは、「pip freeze」で調べると、
matplotlib==1.5.3
となっていました。
回避策
とりあえずは、バージョンを指定してcupyとchainerをインストールすることで回避できます。
インストール済みのcupyとchainerをアンインストール
>pip uninstall cupy
>pip uninstall chainer
バージョンを指定してインストール
>pip install cupy==2.4.0 --no-cache-dir
>pip install chainer==3.4.0 --no-cache-dir
本格対処
Anacondaの最新版である5.1はmatplotが2系になっているので、Anaconda 5.1にすることが対処になります。
以前は、WindowsでPython3.6系のAnadondaを使用すると問題が起きましたが、現在は問題が解決されていました。
Anaconda3 4.2.0をアンインストール
プログラムの追加と削除から「Python 3.5.2 (Anaconda3 4.2.0 64-bit)」をアンインストールします。
Anadonda 5.1のインストール
インストールオプションのInstall for:で、「Just Me」か「All Users」を選択するところで、「Just Me」が推奨になっていますが、ディレクトリ階層が深くなるので「All Users」を選択しました(要Admin権限)。
Advanced Optionsで、「Add Anaconda to the system PATH environment variable」がデフォルトでオフになっていましたが、コマンドラインでpythonコマンドを利用したいのでオンにしました。
pipをアップグレード
python -m pip install --upgrade pip
cupyインストール
以前はWindowsのPython3.6環境でcupyをインストールすると、UnicodeDecodeErrorが発生したが、pipの最新版では問題が改修されておりエラーがでなくなっていました。
>pip install cupy --no-cache-dir
インストール中に以下のエラーが出力されますが、無視しても問題ありません。
notebook 5.4.0 requires ipykernel, which is not installed.
jupyter 1.0.0 requires ipykernel, which is not installed.
jupyter-console 5.2.0 requires ipykernel, which is not installed.
ipywidgets 7.1.1 requires ipykernel>=4.5.1, which is not installed.
chainerインストール
>pip install chainer --no-cache-dir
MNISTサンプル実行
動作確認のためにMNISTサンプルを実行しました。
>git clone https://github.com/chainer/chainer.git
>cd chainer
>cd examples
>cd mnist
>python train_mnist.py -g 0
問題なく実行できました。
C:\Anaconda3\lib\site-packages\h5py\__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
from ._conv import register_converters as _register_converters
GPU: 0
# unit: 1000
# Minibatch-size: 100
# epoch: 20
epoch main/loss validation/main/loss main/accuracy validation/main/accuracy elapsed_time
1 0.191216 0.0942012 0.941517 0.9687 11.5416
2 0.0722713 0.0799588 0.976866 0.9756 14.6657
3 0.0487604 0.0722168 0.984582 0.9789 17.4512
4 0.0362529 0.0650514 0.988115 0.9813 20.3503
5 0.0274124 0.077619 0.990649 0.9808 23.1016
6 0.0228435 0.0733697 0.992465 0.9821 25.9697
7 0.0226351 0.0899091 0.992865 0.9786 28.7722
8 0.0155136 0.0836356 0.994665 0.9809 31.6092
9 0.0160265 0.106787 0.994949 0.9754 34.4846
10 0.0164888 0.0899379 0.994832 0.979 37.3887
11 0.0104961 0.122631 0.996966 0.9771 40.3375
12 0.013743 0.0798696 0.995699 0.9823 43.1569
13 0.0114804 0.121284 0.996465 0.9773 46.0298
14 0.0146573 0.0919883 0.995599 0.9831 48.8832
15 0.0115368 0.100213 0.996949 0.9808 51.6212
16 0.00518552 0.105182 0.998316 0.9822 54.3656
17 0.0141003 0.0964787 0.995815 0.9831 57.1719
18 0.00718431 0.101884 0.998049 0.982 59.9831
19 0.00747319 0.103948 0.997882 0.9816 62.7022
20 0.00940562 0.126561 0.997032 0.9809 65.5354
1行目に警告がでますが、h5pyがNumpyの廃止予定の型を使用しているためですが、特に問題ありません。
2018/8/27追記
以下の警告は、h5pyをアップグレードすることで抑止できます。
C:\Anaconda3\lib\site-packages\h5py\__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
from ._conv import register_converters as _register_converters
h5pyは現在2.8.0がリリースされており、Anaconda 5.1のNumpyのバージョンに対応しています。
バージョン確認
>pip search h5py
h5py (2.8.0) - Read and write HDF5 files from Python
INSTALLED: 2.7.1
LATEST: 2.8.0
アップグレード
>pip install -U h5py