LoginSignup
8
12

More than 5 years have passed since last update.

ディープラーニング向けのUSBデバイス「Movidius Neural Compute Stick」を試す

Last updated at Posted at 2017-11-15

Intelから発売されたMovidius Neural Compute Stickが届いたので、UbuntuにSDKを入れてサンプルプログラムを試してみました。

2017-11-01 17.51.18.jpg

Movidius Neural Compute Stickとは

Movidius Neural Compute StickはIntelが開発したUSB接続タイプのディープラーニング用デバイスです。画像の認識や分析に特化したプロセッサ「Movidius Vision Processing Unit(Myriad 2)」が搭載されていて、ディープラーニングにおける解析処理の際に外部演算装置として使用できます。

USB接続なのでRaspberryPiなどの小型PCでも使えます。貧弱な演算装置しか持たない環境でも、これを使えばデープラーニングを使った画像解析などができるようになるというわけです。

どこで買えるか

公式サイトのこのページに、通販しているサイトがリストアップされています。

8月当時は米国のMouser Electronicsでしか海外発送の取り扱いが無くて、しかも入荷が遅れに遅れて結局届くまで2ヶ月近くかかったんですが、そうこうしてる間に日本の秋月電子スイッチサイエンスでも買えるようになったみたいです。でもMouserの方が79ドル(約9000円、送料無料) だから少し安い。

ちなみにAmazon.co.jpでも売ってるみたいですが、値段が22000円と超ボッタクリ価格なので気をつけましょう。

対応環境

開発環境としてサポートされているOSは、公式では以下の2つとなっています。

  • x86-64 with Ubuntu (64 bit) 16.04 Desktop
  • Raspberry Pi 3 with Raspian Stretch (starting with SDK 1.09.xx)

Ubuntuは仮想マシンでも大丈夫です。公式のインストールガイドではVirtualBoxと書かれていますが、Parallels Desktopでも動きました。

フレームワークとしてはCaffeとTensorFlowがサポートされていて、それぞれサンプルプログラムが用意されています。APIはC++用とPython用があります。

Neural Compute SDKのインストール

今回はParallels Desktop上のUbuntuで試しました。やったことは、概ね公式のインストールガイドで説明されている通りの内容です。

まず、Gitをインストールしていない場合は先に入れておきます。

$ sudo apt install git

pip3もビルドに必要なので入れておきます。

$ sudo apt install python3-pip

Neural Compute Stickの本体をUSBポートに挿します。

IMG_6365.JPG

GitHubから、Neural Compute SDKのリポジトリをcloneしてインストールします。

$ git clone http://github.com/Movidius/ncsdk
$ cd ncsdk
$ make install

サンプルが付属しているので、これもまとめてビルドしておきましょう。

$ make examples

サンプルプログラムを動かす

サンプルプログラムはexampleディレクトリ以下にあります。CaffeとTensorFlowそれぞれのサンプルが用意されています。

CaffeのサンプルはAlexNetとGoogleNet、SqueezeNetの学習済みモデルを使用するものがあります。たとえばGoogleNetのものを試す場合は、examples/caffe/GoogLeNet に降りてmakeします。

$ cd examples/caffe/GoogLeNet
$ make

run.pyが作られるので、これを実行すると次のような結果が出力されます。

$ ./run.py 
Device 0 Address: 4 - VID/PID 03e7:2150
Starting wait for connect with 2000ms timeout
Found Address: 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 905640 bytes...
Successfully sent 905640 bytes of data in 193.816485 ms (4.456203 MB/s)
Boot successful, device address 4
Device 0 Address: 1 - VID/PID 040e:f63b
Found Address: 1 - VID/PID 040e:f63b
done
Booted 1 -> VSC

------- predictions --------
prediction 0 (probability 0.99609) is n03272010 electric guitar  label index is: 546
prediction 1 (probability 0.0035095) is n02676566 acoustic guitar  label index is: 402
prediction 2 (probability 0.0) is n02396427 wild boar, boar, Sus scrofa  label index is: 342
prediction 3 (probability 0.0) is n02391049 zebra  label index is: 340
prediction 4 (probability 0.0) is n02389026 sorrel  label index is: 339

run.py を見ると examples/data/images/nps_electric_guitar.png を決め打ちで推測しているので、推測結果が electric guitar がトップに来ているのは正しい。この run.py を少し書き換えてコマンドライン引数で画像ファイルを指定できるようにすれば、任意の画像を推測できるようになります。

ためしに、このかわいい猫の写真を推測させてみます。あ、うちの猫です。

cat.jpg

$ ./myrun.py ~/cat.jpg 
Device 0 Address: 5 - VID/PID 03e7:2150
Starting wait for connect with 2000ms timeout
Found Address: 5 - 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 905640 bytes...
Successfully sent 905640 bytes of data in 242.535606 ms (3.561067 MB/s)
Boot successful, device address 5
Device 0 Address: 1 - VID/PID 040e:f63b
Found Address: 1 - VID/PID 040e:f63b
done
Booted 1 -> VSC

------- predictions --------
prediction 0 (probability 0.47852) is n02123045 tabby, tabby cat  label index is: 281
prediction 1 (probability 0.25806) is n02124075 Egyptian cat  label index is: 285
prediction 2 (probability 0.12488) is n02123159 tiger cat  label index is: 282
prediction 3 (probability 0.037323) is n02123597 Siamese cat, Siamese  label index is: 284
prediction 4 (probability 0.0084) is n02127052 lynx, catamount  label index is: 287

tabby cat、つまりトラ猫ですね。正解です。0.24秒で認識しているようなので、まずまずではないでしょうか。

TensorFlow用のサンプルも同様に実行できます。ただし、こちらはなぜかビルド後の run.py に実行権限がついていませんでした。

$ cd examples/tensorflow/inception_v3
$ make
$ chmod 755 run.py
$ ./run.py
Number of categories: 1001
Start download to NCS...
*******************************************************************************
inception-v3 on NCS
*******************************************************************************
547 electric guitar 0.98828
403 acoustic guitar 0.0076637
715 pick, plectrum, plectron 0.0014982
421 banjo 0.00092268
820 stage 0.00065422
*******************************************************************************
Finished

学習済みモデルが付いているので、実に手軽に試せるのがいい感じです。

8
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
12