Diary/2017-8-14
Movidius NCS
いくつかのところで話題になっているMovidius NCSに入門.
まずは,URLを参考にセットアップ
https://developer.movidius.com/getting-started
- 1. 環境
- Ubuntu 16.04.
- SDK Movidius(TM) NC SDK 1.07.07 (with Raspberry Pi support)
セットアップ中に必要なファイルをネットワーク経由でダウンロードするので,インターネット接続も必要.
- 2. SDKのセットアップ
下記URLに従う
https://developer.movidius.com/getting-started/software-setup
- 2.1 まずはダウンロードしたアーカイブを展開
miyo@dev:% mkdir -p ~/workspace/mvncsdk miyo@dev:% mv ~/Downloads/MvNC/MvNC_SDK_1.07.07.tgz ~/workspace/mvncsdk miyo@dev:% cd ~/workspace/mvncsdk miyo@dev:% tar xvf MvNC_SDK_1.07.07.tgz
- 2.2 ツールキットのインストール
miyo@dev:% tar xvf MvNC_Toolkit-1.07.06.tgz miyo@dev:% cd bin miyo@dev:% ./setup.sh
デフォルト通り,/opt/movidiusにインストール
インストール後のメッセージは,↓な
Setup is complete. The PYTHONPATH enviroment variable was added to your .bashrc as described in the Caffe documentation. Keep in mind that only newly spawned terminals can see this variable! This means that you need to open a new terminal in order to be able to use the toolkit. Please provide feedback in our support forum if you encountered difficulties.
.bashrcを見てみると,↓の行が.
export PYTHONPATH=$env:"/opt/movidius/caffe/python":$PYTHONPATH
- 2.3 MvNC APIフレームワークのインストール
新しいターミナルでインストールしなさい,とのこと.PYTHONPATHを設定させるため,なんだろうなあ.
普段zsh使いなのだけど,面倒にまきこまれないようにexec bashして実行.
miyo@dev:~$ cd ~/workspace/mvncsdk/ miyo@dev:~/workspace/mvncsdk$ tar xvf MvNC_API-1.07.07.tgz miyo@dev:~/workspace/mvncsdk$ cd ncapi/ miyo@dev:~/workspace/mvncsdk/ncapi$ ./setup.sh
- 3. ツールキットを使ってネットワークのコンパイル
- 3.1 ネットワークのダウンロード
miyo@dev:~$ cd ~/workspace/mvncsdk/bin/data/ miyo@dev:~/workspace/mvncsdk/bin/data$ ./dlnets.sh
- 3.2 Profile, check, and compile
USBポートにNCSを接続してみた
[1012908.672850] usb 2-1.4: new high-speed USB device number 7 using xhci_hcd [1012908.785651] usb 2-1.4: New USB device found, idVendor=03e7, idProduct=2150 [1012908.785655] usb 2-1.4: New USB device strings: Mfr=1, Product=2, SerialNumber=3 [1012908.785657] usb 2-1.4: Product: Movidius MA2X5X [1012908.785658] usb 2-1.4: Manufacturer: Movidius Ltd. [1012908.785660] usb 2-1.4: SerialNumber: 03e72150
で,
miyo@dev:~$ cd ~/workspace/mvncsdk/bin/ miyo@dev:~/workspace/mvncsdk/bin$ make example00
- 4. 推論サンプルの実行
miyo@dev:~$ cd ~/workspace/mvncsdk/ncapi/c_examples miyo@dev:~/workspace/mvncsdk/ncapi/c_examples$ make miyo@dev:~/workspace/mvncsdk/ncapi/c_examples$ ./ncs-fullcheck -l2 -c1 ../networks/AlexNet ../images/cat.jpg Device 0 Address: 1.4 - VID/PID 03e7:2150 Starting wait for connect with 2000ms timeout Found Address: 1.4 - VID/PID 03e7:2150 Found EP 0x81 : max packet size is 512 bytes Found EP 0x01 : max packet size is 512 bytes Found and opened device Performing bulk write of 825136 bytes... Successfully sent 825136 bytes of data in 55.720253 ms (14.122531 MB/s) Boot successful, device address 1.4 Found Address: 1.4 - VID/PID 040e:f63b done Booted 1.4 -> VSC OpenDevice 1.4 succeeded Graph allocated Egyptian cat (69.19%) tabby, tabby cat (6.59%) grey fox, gray fox, Urocyon cinereoargenteus (5.42%) tiger cat (3.93%) hare (3.52%) Inference time: 283.692261 ms, total time 288.112009 ms Deallocate graph, rc=0 Device closed, rc=0
そんなに速くない?と思ったら,-s 12オプションを付けてコンパイルするようにと書いてあったので,
~/workspace/mvncsdk/ncapi/tools/convert_models.shのmvNCCompile.pycのオプションに
"-s 12"を付けてコンパイルして,あらためて実行.
miyo@dev:~/workspace/mvncsdk/ncapi/c_examples$ ./ncs-fullcheck -l2 -c1 ../networks/AlexNet ../images/cat.jpg Device 0 Address: 1.4 - VID/PID 03e7:2150 Starting wait for connect with 2000ms timeout Found Address: 1.4 - VID/PID 03e7:2150 Found EP 0x81 : max packet size is 512 bytes Found EP 0x01 : max packet size is 512 bytes Found and opened device Performing bulk write of 825136 bytes... Successfully sent 825136 bytes of data in 55.787894 ms (14.105408 MB/s) Boot successful, device address 1.4 Found Address: 1.4 - VID/PID 040e:f63b done Booted 1.4 -> VSC OpenDevice 1.4 succeeded Graph allocated Egyptian cat (69.19%) tabby, tabby cat (6.59%) grey fox, gray fox, Urocyon cinereoargenteus (5.42%) tiger cat (3.93%) hare (3.52%) Inference time: 93.080215 ms, total time 97.736447 ms Deallocate graph, rc=0 Device closed, rc=0
3倍くらいは速くなった.
- 補足
ncs-fullcheckが何やってるか,ncs-fullcheck.cの中身をみてみると,要は,
- mvncAllocateGraph で グラフをNCSにロード
- runinference で 実行 (inference_count回)
- mvncDeallocateGraph で グラフをNCSから削除
ということのよう.APIはドキュメント参照とのこと.
- https://ncsforum.movidius.com/discussion/144/api-documentaion
- https://ncs-forum-uploads.s3.amazonaws.com/ncsdk/MvNC_SDK_01_07_07/NCS_API_1.07.07.pdf
ラズパイ3 ベンチマークについても,既に公開されている.
https://ncsforum.movidius.com/discussion/146/raspberry-pi-3-benchmarks?Sort=date