Translate

2019年12月10日火曜日

AWS Greengrass チュートリアル「機械学習の推論を実行する」を試したが何の反応もなかった件

AWS Greengrassのチュートリアルを試している。

チュートリアルの一つ

機械学習の推論を実行する
https://docs.aws.amazon.com/ja_jp/greengrass/latest/developerguide/ml-inference.html

は、
S3上にあるmxnetモデルファイルをロードしてAWS Greengrass Core(デバイス側)上のLambdaで実行してデバイスに装備したカメラで撮影した対象物を予測しその結果を"hello/world"というトピックに返却するというもの。

下の図のSage Maker部分は、チュートリアルでは体験できないが、S3に学習済みモデルファイルをおいてそれをCore上のLambdaが使用するとことは体験できる。



AWS Greengrass Coreは最近買ってきたRaspberry Pi 4B(3B+でも可)にインストールして、上記リンクのとおりに実行してみた...が、動かない..

AWS Greengrass Core 上のログ(エラー)は /greengrass/ggc/var/log/user/<リージョン名>/NNNNNNNNNN/.log というテキストファイルに書き出される。

のぞいてみると

[2019-12-09T07:45:30.002Z][FATAL]-lambda_runtime.py:140,Failed to import handler function "greengrassObjectClassification.function_handler" due to exception: libgfortran.so.3: cannot open shared object file: No such file or directory
[2019-12-09T07:45:30.004Z][FATAL]-lambda_runtime.py:380,Failed to initialize Lambda runtime due to exception: libgfortran.so.3: cannot open shared object file: No such file or directory


というエラーが出ていた。

どうも libgfortran.so.3 というファイルがない、findで探してみると libgfortran.so.5 はあるけど 3 はなかった。

..で、apt install でインストールしようとすると..

pi@gateway:~ $ sudo apt install libgfortran3
Reading package lists... Done
Building dependency tree
Reading state information... Done
You might want to run 'apt --fix-broken install' to correct these.
The following packages have unmet dependencies:
 python-opencv : Depends: python-numpy (>= 1:1.16.0~rc1) but it is not going to be installed
                 Depends: python-numpy-abi9
 python-picamera : Depends: python-numpy but it is not going to be installed
 python-scipy : Depends: python-numpy (>= 1:1.16.0~rc1) but it is not going to be installed
                Depends: python-numpy-abi9
E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).
pi@gateway:~ $

..どうもnumpyが悪さしている様子..

ここはpipでなくaptnumpyをいれてみようということで sudo apt install python-numpy を実行して動かしてみたら、今度はログに


:
[2019-12-10T01:51:58.67Z][ERROR]-[01:51:58] /work/mxnet/src/engine/engine.cc:55: MXNet start using engine: NaiveEngine
[2019-12-10T01:51:59.829Z][ERROR]-csr.py:15,ImportError
[2019-12-10T01:51:59.836Z][ERROR]-csr.py:15,:
[2019-12-10T01:51:59.843Z][ERROR]-csr.py:15,No module named _multiarray_umath
[2019-12-10T01:52:01.69Z][FATAL]-lambda_runtime.py:140,Failed to import handler function "greengrassObjectClassification.function_handler" due to exception: numpy.ufunc size changed, may indicate binary incompatibility. Expected 124 from C header, got 112 from PyObject
[2019-12-10T01:52:01.691Z][FATAL]-lambda_runtime.py:380,Failed to initialize Lambda runtime due to exception: numpy.ufunc size changed, may indicate binary incompatibility. Expected 124 from C header, got 112 from PyObject

  • _multiarray_umath がないよというERROR
  • numpy.ufunc サイズが違うよというFATAL

という2つの問題が発生..


そうか、mxnetがtensorflowを使ってるけど、まだインストールされてなかった。

あわてて sudo pip install tensorflow を実行。


:
  copying h5py/tests/test_vds/test_highlevel_vds.py -> build/lib.linux-armv7l-2.7/h5py/tests/test_vds
  running build_ext
  ('Loading library to get version:', 'libhdf5.so')
  error: libhdf5.so: cannot open shared object file: No such file or directory
  ----------------------------------------
  ERROR: Failed building wheel for h5py
  Running setup.py clean for h5py
Successfully built absl-py wrapt keras-applications termcolor gast
Failed to build h5py
Installing collected packages: funcsigs, mock, absl-py, keras-preprocessing, futures, setuptools, protobuf, grpcio, markdown, werkzeug, tensorboard, wrapt, backports.weakref, h5py, keras-applications, astor, termcolor, gast, google-pasta, tensorflow-estimator, tensorflow

今度は libhdf5.so がないよ..だと..

イライラしつつ sudo apt install libhdf5-dev を実行して、再度hello/worldをサブスクライブしても反応なし..

ログには、

:
[2019-12-10T04:58:46.477Z][FATAL]-lambda_runtime.py:140,Failed to import handler function "greengrassObjectClassification.function_handler" due to exception: numpy.ufunc size changed, may indicate binary incompatibility. Expected 124 from C header, got 112 from PyObject
[2019-12-10T04:58:46.478Z][FATAL]-lambda_runtime.py:380,Failed to initialize Lambda runtime due to exception: numpy.ufunc size changed, may indicate binary incompatibility. Expected 124 from C header, got 112 from PyObject
[2019-12-10T04:58:46.479Z][ERROR]-[04:58:46] /work/mxnet/src/engine/engine.cc:55: MXNet start using engine: NaiveEngine
[2019-12-10T04:58:48.045Z][ERROR]-csr.py:15,ImportError
[2019-12-10T04:58:48.052Z][ERROR]-csr.py:15,:
[2019-12-10T04:58:48.059Z][ERROR]-csr.py:15,No module named _multiarray_umath

..そうか _multiarray_umath の問題を解決できてなかった..

しらべると numpy を最新版にしないといけないらしい。

が、numpy は mxnet の制約上限バージョンでインストールされている..

ままよ、と sudo pip install numpy -U して最新版に更新、Coreデバイスをリブートして、hello/worldをサブスクライブしてみたら..やっと動いた...


うーむ、
AWS Greengrass Core上で動かす Lambda は
AWS上で動かすLambdaと違って
自前で環境を整えないといけない。

現時点のGreengrass CoreはPython2.7なのが厄介だ。

来年には切れる2のサポート問題から、最近のコードは基本 Python3.xで書かれている。

実行ユーザが ggc_user/ggc_group なので、
このユーザにvirtualenvを切ればおそらくPython3.xでも動かせるだろうが、デフォルトの状態ではvirtualenvなしのOSインストール状態のPythonバージョンが適用される。

Raspberry PiのTensorflowも現時点pipできるバージョンは1.14.0

おまけにエラーは、 /greengrass/ggc/var/log/user/<リージョン名>/NNNNNNNNNN/.log を覗かないとわからない..




そしてもっとも厄介なのが、この情報がいま時点では、ということ。
明日には変わっているかもしれない..

AWS Greengras Core 環境整備がとても大変だ..

本番だとCoreを複数立てるわけだろうし..

かなり厄介だな、IoT ゲートウェイって..



ps 2020/02/18追記

ROSのインストールをはじめて
最新バージョンであるmelodicですらいまだpython2.7を使っていることに気づいてから..
ずっともやもやしてたけど..

やっぱりAWS Greengrass は ROS のソースコードをパクっているんだろうなあ..

いや、ROSのライセンスはBSDだったはずなので、駄目というわけではないのだけど..

ROS モジュールをAWSコンソールからインストールできるからいいのだけどね..

0 件のコメント:

既存アプリケーションをK8s上でコンテナ化して動かす場合の設計注意事項メモ

既存アプリをK8sなどのコンテナにして動かすには、どこを注意すればいいか..ちょっと調べたときの注意事項をメモにした。   1. The Twelve Factors (日本語訳からの転記) コードベース   バージョン管理されている1つのコードベースと複数のデプロイ 依存関係 ...