Intel Neural Compute Stick 2の動作確認

AI

Intel Neural Compute Stick2(NCS2)をRaspberry Pi 3で動作させた時のメモです。

NCS2の概要

  • USBで機器に接続して利用するディープラーニング推論のアクセラレータ。
  • 製造中止が決まっている。テクニカルサポートは2023年6月30日まで。保証サポートは2024年6月30日まで。
  • OpenVINOは2022.3までNCS2をサポート。

Raspberry PiのOSバージョン

Install OpenVINO toolkit for Raspbian OSによると、BusterかStretchで動作確認が行われているので、Busterを使用します。

$ lsb_release -a
No LSB modules are available.
Distributor ID: Raspbian
Description:    Raspbian GNU/Linux 10 (buster)
Release:        10
Codename:       buster

ARMのアーキテクチャを確認します。今回の動作確認はARMアーキテクチャ(armv7l)で動作します。このため、初期のRaspberry Piでは動作しません。

$ uname -m
armv7l

動作確認

OpenVINOランタイムのダウンロード

Raspberry Piにログインして、ターミナルからOpenVINO 2021.4のランタイムをダウンロードします。

$wget "https://storage.openvinotoolkit.org/repositories/openvino/packages/2021.4.2/l_openvino_toolkit_runtime_raspbian_p_2021.4.752.tgz"

データを展開して/opt/intelpenvino_2021.4にリネームします。

$sudo mkdir /opt/intel
$sudo mv l_openvino_toolkit_runtime_raspbian_p_2021.4.752 /opt/intel/openvino_2021.4/

環境変数を設定します。

$source /opt/intel/openvino_2021.4/bin/setupvars.sh
[setupvars.sh] OpenVINO environment initialized

NCS2のセットアップ

ユーザーをusersグループに追加します。

$sudo usermod -a -G users "$(whoami)"

USBのルールを追加します。

$sudo cp /opt/intel/openvino_2021.4/inference_engine/external/97-myriad-usbboot.rules /etc/udev/rules.d/
$sudo udevadm control --reload-rules
$sudo udevadm trigger
$sudo ldconfig

NCS2が認識されることを確認します。

$ lsusb
Bus 001 Device 006: ID 03e7:2485 Intel Movidius MyriadX
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp. SMC9514 Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

サンプルの動作確認

cmakeをインストールします。

$sudo apt install cmake -y

サンプルをコンパイします。

$mkdir sample
$cd sample
$cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-march=armv7-a" /opt/intel/openvino_2021.4/deployment_tools/inference_engine/samples/cpp
$make -j2 object_detection_sample_ssd

モデルのダウンロード

公式サイトの解説ではgithubからopen_model_zooをcloneしてpythonでモデルを生成していますが、モデルのバージョン不一致などで次のようなエラーが発生しました。

[ ERROR ] Unknown model format! Cannot find reader for model format: xml and read the model: /home/guest/sample/open_model_zoo/tools/model_tools/intel/face-detection-adas-0001/FP16/face-detection-adas-0001.xml. Please check that reader library exists in your PATH.

色々と試行錯誤してもモデルの生成に成功しなかったため、モデルを生成する代わりに、生成済みのモデルをダウンロードすることにしました。ダウンロードするモデルのバージョンは、OpenVINOのバージョンに合わせる必要があります。

$pwd
$sample
$mkdir open_model_zoo
$cd open_model_zoo
$wget https://storage.openvinotoolkit.org/repositories/open_model_zoo/2021.4/models_bin/2/face-detection-adas-0001/FP16/face-detection-adas-0001.xml
$wget https://storage.openvinotoolkit.org/repositories/open_model_zoo/2021.4/models_bin/2/face-detection-adas-0001/FP16/face-detection-adas-0001.bin

テスト画像の用意

GoogleのOpen Images Datasetの画像をテスト画像として使用します。

ID: 8a8cf97afe36b4dc Title: DK Friends The Adventure Guide
ID: 8a8cf97afe36b4dc Title: DK Friends The Adventure Guide

推論の実行

$./armv7l/Release/object_detection_sample_ssd -m /home/guest/sample/open_model_zoo/face-detection-adas-0001.xml -i ./test.jpg -d MYRIAD
[ INFO ] InferenceEngine: 
	IE version ......... 2021.4.2
	Build ........... 2021.4.2-3974-e2a469a3450-releases/2021/4
Parsing input parameters
[ INFO ] Files were added: 1
[ INFO ]     ./test.jpg
[ INFO ] Loading Inference Engine
[ INFO ] Device info: 
	MYRIAD
	myriadPlugin version ......... 2021.4.2
	Build ........... 2021.4.2-3974-e2a469a3450-releases/2021/4

[ INFO ] Loading network files:
[ INFO ] /home/guest/sample/open_model_zoo/face-detection-adas-0001.xml
[ INFO ] Preparing input blobs
[ INFO ] Batch size is 1
[ INFO ] Preparing output blobs
[ INFO ] Loading model to the device
[ INFO ] Create infer request
[ WARNING ] Image is resized from (1058, 1280) to (672, 384)
[ INFO ] Batch size is 1
[ INFO ] Start inference
[ INFO ] Processing output blobs
[0,1] element, prob = 1    (193,766)-(318,907) batch id : 0 WILL BE PRINTED!
[1,1] element, prob = 0.996582    (576,793)-(706,945) batch id : 0 WILL BE PRINTED!
[2,1] element, prob = 0.960449    (370,782)-(505,937) batch id : 0 WILL BE PRINTED!
[3,1] element, prob = 0.912598    (20,775)-(147,950) batch id : 0 WILL BE PRINTED!
[4,1] element, prob = 0.251465    (845,951)-(884,1005) batch id : 0
[5,1] element, prob = 0.0375977    (853,632)-(892,685) batch id : 0
[6,1] element, prob = 0.0356445    (523,841)-(587,937) batch id : 0
[7,1] element, prob = 0.034668    (821,918)-(879,997) batch id : 0
[8,1] element, prob = 0.0332031    (827,1041)-(864,1103) batch id : 0
[9,1] element, prob = 0.0283203    (799,1022)-(838,1085) batch id : 0
[10,1] element, prob = 0.0283203    (773,766)-(846,873) batch id : 0
[11,1] element, prob = 0.0283203    (428,813)-(514,925) batch id : 0
[12,1] element, prob = 0.0268555    (926,638)-(963,698) batch id : 0
[13,1] element, prob = 0.0258789    (-7,787)-(69,962) batch id : 0
[14,1] element, prob = 0.0249023    (90,540)-(144,662) batch id : 0
[15,1] element, prob = 0.0249023    (796,947)-(858,1030) batch id : 0
[16,1] element, prob = 0.0239258    (867,956)-(907,1014) batch id : 0
[17,1] element, prob = 0.0239258    (825,1020)-(861,1081) batch id : 0
[18,1] element, prob = 0.0239258    (841,1048)-(879,1112) batch id : 0
[19,1] element, prob = 0.0239258    (785,1047)-(849,1118) batch id : 0
[20,1] element, prob = 0.0229492    (771,1010)-(821,1079) batch id : 0
[21,1] element, prob = 0.0229492    (13,716)-(118,904) batch id : 0
[22,1] element, prob = 0.0219727    (788,887)-(848,982) batch id : 0
[23,1] element, prob = 0.0209961    (612,301)-(652,361) batch id : 0
[24,1] element, prob = 0.0209961    (344,349)-(380,414) batch id : 0
[25,1] element, prob = 0.0209961    (626,365)-(660,425) batch id : 0
[26,1] element, prob = 0.0209961    (749,793)-(788,863) batch id : 0
[27,1] element, prob = 0.0209961    (775,796)-(810,856) batch id : 0
[28,1] element, prob = 0.0209961    (89,452)-(146,549) batch id : 0
[29,1] element, prob = 0.0209961    (830,566)-(908,686) batch id : 0
[30,1] element, prob = 0.0200195    (94,532)-(130,601) batch id : 0
[31,1] element, prob = 0.0200195    (778,956)-(812,1016) batch id : 0
[32,1] element, prob = 0.0200195    (803,959)-(838,1018) batch id : 0
[33,1] element, prob = 0.0200195    (735,684)-(792,763) batch id : 0
[34,1] element, prob = 0.0200195    (680,727)-(752,830) batch id : 0
[35,1] element, prob = 0.0200195    (706,791)-(773,898) batch id : 0
[36,1] element, prob = 0.0200195    (483,828)-(549,924) batch id : 0
[37,1] element, prob = 0.0200195    (763,810)-(829,913) batch id : 0
[38,1] element, prob = 0.0200195    (778,998)-(861,1108) batch id : 0
[39,1] element, prob = 0.0200195    (431,1195)-(499,1274) batch id : 0
[40,1] element, prob = 0.019043    (867,630)-(904,690) batch id : 0
[41,1] element, prob = 0.019043    (528,850)-(564,924) batch id : 0
[42,1] element, prob = 0.019043    (709,835)-(764,918) batch id : 0
[43,1] element, prob = 0.019043    (801,907)-(835,963) batch id : 0
[44,1] element, prob = 0.019043    (832,954)-(870,1009) batch id : 0
[45,1] element, prob = 0.019043    (804,1049)-(836,1111) batch id : 0
[46,1] element, prob = 0.019043    (101,521)-(159,628) batch id : 0
[47,1] element, prob = 0.019043    (-4,623)-(41,806) batch id : 0
[48,1] element, prob = 0.019043    (767,676)-(830,761) batch id : 0
[49,1] element, prob = 0.019043    (742,779)-(811,875) batch id : 0
[50,1] element, prob = 0.019043    (12,808)-(96,935) batch id : 0
[51,1] element, prob = 0.019043    (806,826)-(868,920) batch id : 0
[52,1] element, prob = 0.019043    (296,861)-(376,1012) batch id : 0
[53,1] element, prob = 0.019043    (770,946)-(821,1043) batch id : 0
[54,1] element, prob = 0.019043    (763,1066)-(826,1140) batch id : 0
[55,1] element, prob = 0.019043    (17,601)-(131,812) batch id : 0
[56,1] element, prob = 0.019043    (37,945)-(268,1350) batch id : 0
[57,1] element, prob = 0.019043    (270,110)-(956,921) batch id : 0
[58,1] element, prob = 0.0180664    (119,472)-(155,533) batch id : 0
[59,1] element, prob = 0.0180664    (830,628)-(863,686) batch id : 0
[60,1] element, prob = 0.0180664    (851,683)-(885,740) batch id : 0
[61,1] element, prob = 0.0180664    (13,723)-(59,825) batch id : 0
[62,1] element, prob = 0.0180664    (728,798)-(759,863) batch id : 0
[63,1] element, prob = 0.0180664    (797,798)-(836,858) batch id : 0
[64,1] element, prob = 0.0180664    (776,851)-(809,910) batch id : 0
[65,1] element, prob = 0.0180664    (0,880)-(33,956) batch id : 0
[66,1] element, prob = 0.0180664    (536,888)-(587,958) batch id : 0
[67,1] element, prob = 0.0180664    (844,1008)-(884,1078) batch id : 0
[68,1] element, prob = 0.0180664    (876,1010)-(911,1065) batch id : 0
[69,1] element, prob = 0.0180664    (902,1008)-(933,1065) batch id : 0
[70,1] element, prob = 0.0180664    (969,1110)-(1012,1168) batch id : 0
[71,1] element, prob = 0.0180664    (594,345)-(645,428) batch id : 0
[72,1] element, prob = 0.0180664    (841,591)-(894,668) batch id : 0
[73,1] element, prob = 0.0180664    (905,598)-(981,721) batch id : 0
[74,1] element, prob = 0.0180664    (0,636)-(73,836) batch id : 0
[75,1] element, prob = 0.0180664    (0,819)-(49,931) batch id : 0
[76,1] element, prob = 0.0180664    (663,808)-(760,938) batch id : 0
[77,1] element, prob = 0.0180664    (734,818)-(792,913) batch id : 0
[78,1] element, prob = 0.0180664    (-9,870)-(46,974) batch id : 0
[79,1] element, prob = 0.0180664    (670,898)-(753,1033) batch id : 0
[80,1] element, prob = 0.0180664    (884,989)-(940,1080) batch id : 0
[81,1] element, prob = 0.0180664    (958,1128)-(1081,1302) batch id : 0
[82,1] element, prob = 0.0180664    (716,147)-(1032,818) batch id : 0
[83,1] element, prob = 0.0170898    (15,264)-(51,343) batch id : 0
[84,1] element, prob = 0.0170898    (548,320)-(584,386) batch id : 0
[85,1] element, prob = 0.0170898    (579,307)-(618,372) batch id : 0
[86,1] element, prob = 0.0170898    (601,308)-(640,370) batch id : 0
[87,1] element, prob = 0.0170898    (551,358)-(585,421) batch id : 0
[88,1] element, prob = 0.0170898    (573,423)-(612,492) batch id : 0
[89,1] element, prob = 0.0170898    (406,460)-(439,519) batch id : 0
[90,1] element, prob = 0.0170898    (497,470)-(527,529) batch id : 0
[91,1] element, prob = 0.0170898    (853,595)-(882,651) batch id : 0
[92,1] element, prob = 0.0170898    (879,587)-(907,646) batch id : 0
[93,1] element, prob = 0.0170898    (924,594)-(959,653) batch id : 0
[94,1] element, prob = 0.0170898    (904,640)-(941,703) batch id : 0
[95,1] element, prob = 0.0170898    (771,749)-(819,824) batch id : 0
[96,1] element, prob = 0.0170898    (800,749)-(835,809) batch id : 0
[97,1] element, prob = 0.0170898    (15,835)-(64,916) batch id : 0
[98,1] element, prob = 0.0170898    (524,890)-(564,953) batch id : 0
[99,1] element, prob = 0.0170898    (779,900)-(811,960) batch id : 0
[ INFO ] Image out_0.bmp created!
[ INFO ] Execution successful

[ INFO ] This sample is an API example, for any performance measurements please use the dedicated benchmark_app tool

結果の確認

顔として認識した領域を付与した画像(out_0.bmp)が生成されます。

out_0.bmp
out_0.bmp
タイトルとURLをコピーしました