謎のARMアクセラレータ

本日、謎のARMアクセラレータが届きました。

中身はCoralと言って「EDGE TPU COPROCESSOR」でした。

こんな感じです。

セットアップ

セットアップ環境はUbuntu 18.04.1LTSです。

下記のURLを参照しながらチュートリアルを進めます。

https://coral.withgoogle.com/tutorials/accelerator/

Setup for Linux or Raspberry Pi

とりあえず、APIのインストールをします。

wget http://storage.googleapis.com/cloud-iot-edge-pretrained-models/edgetpu_api.tar.gz
tar xzf edgetpu_api.tar.gz
cd python-tflite-source
bash ./install.sh

Ubuntu 18.04ではPythonが3.6なので次のエラーが発生します。

./install.sh: line 96: python3.5: command not found

Python 3.5インストール

次のようにPython 3.5をインストールします。

wget https://www.python.org/ftp/python/3.5.6/Python-3.5.6.tgz
tar xzf Python-3.5.6.tgz
cd Python-3.5.6
./configure --enable-optimizations
sudo make altinstall

インストールの再開

Python 3.5をインストールできたらAPIのインストールを再開します。

bash ./install.sh

念の為、udevを確認します。

$ cat /etc/udev/rules.d/99-edgetpu-accelerator.rules
SUBSYSTEM=="usb",ATTRS{idVendor}=="1a6e",GROUP="plugdev"
SUBSYSTEM=="usb",ATTRS{idVendor}=="18d1",GROUP="plugdev"

さらに念の為、udevを再読み込みます。

sudo udevadm control --reload-rules

USBを確認してみます。

$ lsusb
Bus 002 Device 004: ID 1a6e:089a Global Unichip Corp.

googleじゃないんだ・・・

サンプルの実行

サンプルを実行してみます。

cd edgetpu/
$ time python3.5 demo/classify_image.py \
--model test_data/mobilenet_v2_1.0_224_inat_bird_quant_edgetpu.tflite \
--label test_data/inat_bird_labels.txt \
--image test_data/parrot.jpg
---------------------------
Ara macao (Scarlet Macaw)
Score :  0.61328125
---------------------------
Platycercus elegans (Crimson Rosella)
Score :  0.15234375

real    0m3.035s
user    0m0.338s
sys     0m0.045s

もうひとつ、サンプルを実行してみます。

"--output"を付けると結果を出力することができます。

$ time python3.5 demo/object_detection.py \
--model test_data/mobilenet_ssd_v2_face_quant_postprocess_edgetpu.tflite \
--input test_data/face.jpg \
--output ~/detection_results.jpg
-----------------------------------------
score =  0.99609375
box =  [474.22854804992676, 38.03488787482766, 738.8013491630554, 353.5309683683231]
-----------------------------------------
score =  0.9921875
box =  [205.4297697544098, 110.28378465056959, 487.75309658050537, 439.73802454331343]
-----------------------------------------
score =  0.83203125
box =  [6.2277887016534805, 182.35811898071842, 127.13575917482376, 326.5376813379348]
-----------------------------------------
score =  0.5
box =  [859.8422718048096, 213.5472493581642, 1008.978108882904, 383.9367261515483]

real    0m3.094s
user    0m0.401s
sys     0m0.046s

その他

結構、暖かくなります。

write: 2019/03/09/ 00:35:04