Custom Vision on IoT Edge v2 (Docker) on Raspberry Pi
この記事の続きです。
前回は、Custom VisionのClassificationをDockerFileエクスポートして、UPボード(Ubuntu Server 16.04)で動かしました。今回は、このDockerFileエクスポートをRaspberry Pi 3 Model Bで動かしてみます。
RaspbianとDockerをインストール
過去記事のStep 1からStep 4までを実施して、Raspberry PiにRaspbianとDockerをインストールします。
過去記事のときのRaspbianは2018-03-13-raspbian-stretch-lite.imgでしたが、現在の最新は2018-04-18-raspbian-stretch-lite.imgなので、最新を使ってください。
なお、インストールされたDockerのバージョンは18.05.00でした。
$ docker --version Docker version 18.05.0-ce, build f150324
DockerでCustomVisionを起動
Custom VisionでDockerFileエクスポートしたzipファイルをRaspberry Piにコピー、解凍して、docker buildします。
(やっぱりDockerFileはDockerfileにリネームが必要でした。)
すると、、、
No matching distribution found for tensorflow==1.5.0というエラーが発生して死亡orz

PyPIのtensorflow 1.5.0にarmのパッケージがアップされていないのが原因のようです。
Dockerfileとrequirements.txt
//Build2018 Vision Keynoteのscott-or-notのソースがgithubに公開されている情報をキャッチしていたので、それを丸写しに参考にDockerfileとapp/requirements.txtを書きかえてみました。
さっくるさん情報。アンテナはっておくの大事ですねw
先程のbuildのIoT Edgeのデモのscott-or-notのアプリの作り方です。ラズパイでCustom Visionのモデルを使ったローカル画像認識が簡単にできるようになりました(`・∀・´) #msbuild https://t.co/k4qUjTAcGq
— さっくる / Saki (@sakkuru) 2018年5月7日
で、書き換えたDockerfileとapp/requirements.txtはこちら。
Dockerfile
FROM resin/rpi-raspbian:jessie
ADD app /app
# Install dependencies
RUN apt-get update && apt-get install -y \
python3 \
python3-pip \
wget \
build-essential \
libjpeg-dev \
python3-dev \
zlib1g-dev
RUN pip3 install --upgrade pip
RUN pip install --upgrade setuptools
RUN pip install -r /app/requirements.txt
RUN pip install http://ci.tensorflow.org/view/Nightly/job/nightly-pi-python3/179/artifact/output-artifacts/tensorflow-1.7.0-cp34-none-any.whl
# Expose the port
EXPOSE 80
# Set the working directory
WORKDIR /app
# Run the flask server for the endpoints
CMD python3 app.py
app/requirements.txt
requests Pillow Flask numpy
DockerでCustomVisionを起動(2回目)
動いたー!
$ docker build -t wio-module . $ docker images REPOSITORY TAG IMAGE ID CREATED SIZE wio-module latest 6cc21d1089d4 7 seconds ago 739MB resin/rpi-raspbian jessie 248c8313f621 3 days ago 126MB $ docker run -p 127.0.0.1:80:80 -d wio-module 5d455f69689c03de931e5168d938690a7e50b9563dfdf2e8c0aea7a7151e8e59
画像を投げてみる。
$ time curl -X POST http://127.0.0.1/image -H "Content-Type: application/octet-stream" --data-binary @IMG_0015.JPG
{"created":"2018-05-12T15:47:10.400908","id":"","iteration":"","predictions":[{"boundingBox":null,"probability":0.9996511936187744,"tagId":"","tagName":"Wio LTE"}],"project":""}
real 0m3.353s
user 0m0.031s
sys 0m0.040s
$ docker logs 5d455f69689c
Loading model...Success!
Loading labels...2 found. Success!
* Serving Flask app "app" (lazy loading)
* Environment: production
WARNING: Do not use the development server in a production environment.
Use a production WSGI server instead.
* Debug mode: off
* Running on http://0.0.0.0:80/ (Press CTRL+C to quit)
172.17.0.1 - - [12/May/2018 15:47:01] "POST /image HTTP/1.1" 200 -
メモリ使用量は、、、なんか表示されないなぁ。
$ docker stats 5d455f69689c CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS 5d455f69689c practical_mcclintock 0.04% 0B / 0B 0.00% 3.07MB / 12.6kB 13.6MB / 0B 0
感想
- CustomVision、Raspberry Piでも動いた。
- 環境構築に時間がかかった。すんなりできてもトータル2時間くらい?