Raspberry Pi を利用した機械学習について試す。
Contents
OpenCV、TensorFlow、Kerasをインストール
3 wget https://github.com/mt08xx/files/raw/master/opencv-rpi/libopencv3_3.4.0-20180115.1_armhf.deb
4 sudo apt install -y ./libopencv3_3.4.0-20180115.1_armhf.deb
5 sudo ldconfig
6 pip3 install numpy==1.13
7 sudo apt-get install libblas-dev liblapack-dev python3-dev libatlas-base-dev gfortran python3-setuptools
8 sudo pip3 install https://github.com/lhelontra/tensorflow-on-arm/releases/download/v1.8.0/tensorflow-1.8.0-cp35-none-linux_armv7l.whl
10 sudo apt-get install python3-h5py
11 sudo pip3 install keras==2.1.6
画像判別サンプル
12 git clone https://github.com/karaage0703/keras-pi
13 cd keras-pi
テスト用のカメラ画像を用いて判別(1)
14 python3 pred.py -l ./model/labels.txt -m ./model/mnist_deep_model.json -w ./model/weights.99.hdf5 -t ./data/test.jpg
次のエラーで撃沈
RuntimeError: module compiled against API version 0xc but this version
of numpy is 0xb
RuntimeError: module compiled against API version 0xc but this version
of numpy is 0xb
RuntimeError: module compiled against API version 0xc but this version
of numpy is 0xb
テスト用のカメラ画像を用いて判別(2)
numpyをアップデートして、再度試す。
15 python3 -c “import jupyter, matplotlib, numpy, scipy, sklearn
16 pip install -U numpy
17 python3 pred.py -l ./model/labels.txt -m ./model/mnist_deep_model.json -w ./model/weights.99.hdf5 -t ./data/test.jpg
同じエラーで撃沈
RuntimeError: module compiled against API version 0xc but this version
of numpy is 0xb
RuntimeError: module compiled against API version 0xc but this version
of numpy is 0xb
RuntimeError: module compiled against API version 0xc but this version
of numpy is 0xb
では、keras==2.1.6にしたら、どうでしょうか?
23 sudo pip3 install keras==2.1.6
結果は同じエラー。
テスト用のカメラ画像を用いて判別(3)
pi@raspberrypi:~ $
pi@raspberrypi:~ $ python3
Python 3.5.3 (default, Sep 27 2018, 17:25:39)
[GCC 6.3.0 20170516] on linux
Type “help”, “copyright”, “credits” or “license” for more information.
>>> import keras
Using TensorFlow backend.
RuntimeError: module compiled against API version 0xc but this version
of numpy is 0xb
RuntimeError: module compiled against API version 0xc but this version
of numpy is 0xb
RuntimeError: module compiled against API version 0xc but this version
of numpy is 0xb
Traceback (most recent call last):
File “<stdin>”, line 1, in <module>
File “/usr/local/lib/python3.5/dist-packages/keras/__init__.py”,
line 3, in <module>
from . import utils
File “/usr/local/lib/python3.5/dist-packages/keras/utils/__init__.py”,
line 25, in <module>
from .multi_gpu_utils import multi_gpu_model
File “/usr/local/lib/python3.5/dist-packages/keras/utils/multi_gpu_utils.py”,
line 7, in <module>
from ..layers.merge import concatenate
File “/usr/local/lib/python3.5/dist-packages/keras/layers/__init__.py”,
line 4, in <module>
from ..engine import Layer
File “/usr/local/lib/python3.5/dist-packages/keras/engine/__init__.py”,
line 8, in <module>
from .training import Model
File “/usr/local/lib/python3.5/dist-packages/keras/engine/training.py”,
line 11, in <module>
from scipy.sparse import issparse
File “/usr/local/lib/python3.5/dist-packages/scipy/sparse/__init__.py”,
line 229, in <module>
from .csr import *
File “/usr/local/lib/python3.5/dist-packages/scipy/sparse/csr.py”,
line 15, in <module>
from ._sparsetools import csr_tocsc, csr_tobsr, csr_count_blocks, \
ImportError: numpy.core.multiarray failed to import
>>> exit
Use exit() or Ctrl-D (i.e. EOF) to exit
>>>
pi@raspberrypi:~ $ sudo pip3 install keras==2.1.6
Requirement already satisfied: keras==2.1.6 in
/usr/local/lib/python3.5/dist-packages
Requirement already satisfied: pyyaml in
/usr/local/lib/python3.5/dist-packages (from keras==2.1.6)
Requirement already satisfied: scipy>=0.14 in
/usr/local/lib/python3.5/dist-packages (from keras==2.1.6)
Requirement already satisfied: numpy>=1.9.1 in
/usr/local/lib/python3.5/dist-packages (from keras==2.1.6)
Requirement already satisfied: six>=1.9.0 in
/usr/lib/python3/dist-packages (from keras==2.1.6)
Requirement already satisfied: h5py in /usr/lib/python3/dist-packages
(from keras==2.1.6)
pi@raspberrypi:~ $
すでにインストールされている。結果は同じ。
テスト用のカメラ画像を用いて判別(4)
numpy==1.13にしたら、どうでしょうか?
pi@raspberrypi:~ $ sudo pip3 install numpy==1.13
Collecting numpy==1.13
Downloading https://www.piwheels.org/simple/numpy/numpy-1.13.0-cp35-cp35m-linux_armv7l.whl (6.1MB)
100% |████████████████████████████████| 6.1MB 23kB/s
Installing collected packages: numpy
Found existing installation: numpy 1.15.4
Uninstalling numpy-1.15.4:
Successfully uninstalled numpy-1.15.4
Successfully installed numpy-1.13.0
pi@raspberrypi:~ $ cd keras-pi
pi@raspberrypi:~/keras-pi $ python3 pred.py -l ./model/labels.txt -m ./model/mnist_deep_model.json -w ./model/weights.99.hdf5 -t ./data/test.jpg
Using TensorFlow backend.
RuntimeError: module compiled against API version 0xc but this version of numpy is 0xb
RuntimeError: module compiled against API version 0xc but this version of numpy is 0xb
RuntimeError: module compiled against API version 0xc but this version of numpy is 0xb
Traceback (most recent call last):
File “pred.py”, line 6, in <module>
from keras.preprocessing.image import array_to_img, img_to_array, load_img
File “/usr/local/lib/python3.5/dist-packages/keras/__init__.py”, line 3, in <module>
from . import utils
File “/usr/local/lib/python3.5/dist-packages/keras/utils/__init__.py”, line 25, in <module>
from .multi_gpu_utils import multi_gpu_model
File “/usr/local/lib/python3.5/dist-packages/keras/utils/multi_gpu_utils.py”, line 7, in <module>
from ..layers.merge import concatenate
File “/usr/local/lib/python3.5/dist-packages/keras/layers/__init__.py”, line 4, in <module>
from ..engine import Layer
File “/usr/local/lib/python3.5/dist-packages/keras/engine/__init__.py”, line 8, in <module>
from .training import Model
File “/usr/local/lib/python3.5/dist-packages/keras/engine/training.py”, line 11, in <module>
from scipy.sparse import issparse
File “/usr/local/lib/python3.5/dist-packages/scipy/sparse/__init__.py”, line 229, in <module>
from .csr import *
File “/usr/local/lib/python3.5/dist-packages/scipy/sparse/csr.py”, line 15, in <module>
from ._sparsetools import csr_tocsc, csr_tobsr, csr_count_blocks, \
ImportError: numpy.core.multiarray failed to import
pi@raspberrypi:~/keras-pi $
結果も同じだ!