LoginSignup
4
3

More than 5 years have passed since last update.

RasPi : Movidius ニューラル・コンピュート・スティックで遊ぶ♬

Last updated at Posted at 2018-06-02

このIntel® Movidius™ Neural Compute Stickは、イメージ最高。。。1万円でRasPiが高性能なDLマシンになっちゃう♬

ということで、半年以上たったので安定しているはずということで試してみました。
というか、RasPi使っていろいろ物体検出とかやれそうだなということで期待してやってみました。

結果から書くと、出来ました!
残念ながら、ここにたどり着けたのは幸運だったかもしれません。
ということで、苦労話は無しで、マネしてもらえればほぼ出来ると思います。
※参考はたくさんありますが、。。すべての記載は控えます

メモリは4GB以上空きがないと厳しいと思います。
※ウワンはSTRETCH完了時2GB残ってましたが、途中削除しつつ進めましたが最後はぎりぎりになりました

やるべきこと

(1)ほぼ公式のとおりやる

Intel® Movidius™ NCS Quick Start
つまり、
1. You will need the following:購入
   ⇒じゃなくて、JessieからUbuntuかStretchのインストール
   ちなみに、前提のOSは以下のとおりです。
  • Ubuntu 16.04 system, RPI3 Model B or Ubuntu VirtualBox instance.
2. Install NC SDK:インストール
3. Test installation by running built-in examples
4. Next steps
  Visit our github repo for more examples.   
  https://developer.movidius.com/examples

1. JessieからStretchにアップグレード

Raspbian GNU/Linux upgrade from Jessie to Raspbian Stretch 9
【参考】
メモ (らずぱい) Raspbian: Jessie から Stretchへアップグレード

ここはただひたすら上記のコマンドたたいて、待ちます。
英語のページは怖いこと書いてありますが見た目が変わったり以外、トラブルは。。ありませんでした。
しかし、サードパーティーとして、OpenCVが出るのでぎょっとしました。
削除しがたい。。。

2. Install NC SDK:インストール

ここも単に以下のコマンドたたくだけ、
最後のところは書込みエラー発生したのでsudo付けました。

Run these commands on a terminal window
mkdir -p ~/workspace
cd ~/workspace
git clone https://github.com/movidius/ncsdk.git
cd ~/workspace/ncsdk
make install

ただし、この最後のinstallは6時間位覚悟した方がいいです。
そして、ウワンの環境だと、dpkgの警告が何度か出ていましたが、ほぼ以下のとおり、無事に終了。

-- Could NOT find Boost
CMake Warning at /usr/share/cmake-3.7/Modules/FindBoost.cmake:1534 (message):
  No header defined for python-py35; skipping header check
Call Stack (most recent call first):
  cmake/Dependencies.cmake:131 (find_package)
  CMakeLists.txt:43 (include)

-- Boost version: 1.62.0
-- Found the following Boost libraries:
--   python-py35
-- Could NOT find Doxygen (missing:  DOXYGEN_EXECUTABLE) 
-- 
-- ******************* Caffe Configuration Summary *******************
-- General:
--   Version           :   1.0.0-rc3
--   Git               :   ssdv1.0-dirty
--   System            :   Linux
--   C++ compiler      :   /usr/bin/c++
--   Release CXX flags :   -O3 -DNDEBUG -fPIC -Wall -Wno-sign-compare -Wno-uninitialized
--   Debug CXX flags   :   -g -fPIC -Wall -Wno-sign-compare -Wno-uninitialized
--   Build type        :   Release
-- 
--   BUILD_SHARED_LIBS :   ON
--   BUILD_python      :   ON
--   BUILD_matlab      :   OFF
--   BUILD_docs        :   ON
--   CPU_ONLY          :   ON
--   USE_OPENCV        :   ON
--   USE_LEVELDB       :   ON
--   USE_LMDB          :   ON
--   ALLOW_LMDB_NOLOCK :   OFF
-- 
-- Dependencies:
--   BLAS              :   Yes (Atlas)
--   Boost             :   Yes (ver. 1.62)
--   glog              :   Yes
--   gflags            :   Yes
--   protobuf          :   Yes (ver. 3.0.0)
--   lmdb              :   Yes (ver. 0.9.18)
--   LevelDB           :   Yes (ver. 1.18)
--   Snappy            :   Yes (ver. 1.1.3)
--   OpenCV            :   Yes (ver. 2.4.9.1)
--   CUDA              :   No
-- 
-- Python:
--   Interpreter       :   /usr/bin/python3 (ver. 3.5.3)
--   Libraries         :   /usr/lib/arm-linux-gnueabihf/libpython3.5m.so (ver 3.5.3)
--   NumPy             :   /usr/local/lib/python3.5/dist-packages/numpy/core/include (ver 1.13.1)
-- 
-- Documentaion:
--   Doxygen           :   No
--   config_file       :   
-- 
-- Install:
--   Install path      :   /opt/movidius/ssd-caffe/build/install
-- 
-- Configuring done
-- Generating done
-- Build files have been written to: /opt/movidius/ssd-caffe/build

エラー出てますが。。。継続します

Processing /opt/movidius/NCSDK/ncsdk-armv7l/api
Installing collected packages: mvnc
  Found existing installation: mvnc 1.12.0.1
    Uninstalling mvnc-1.12.0.1:
      Successfully uninstalled mvnc-1.12.0.1
  Running setup.py install for mvnc: started
    Running setup.py install for mvnc: finished with status 'done'
Successfully installed mvnc-1.12.0.1
Processing /opt/movidius/NCSDK/ncsdk-armv7l/api
Building wheels for collected packages: mvnc
  Running setup.py bdist_wheel for mvnc: started
  Running setup.py bdist_wheel for mvnc: finished with status 'done'
  Stored in directory: /tmp/pip-ephem-wheel-cache-h_DgoH/wheels/17/b6/ed/2477b3035457946ce3a1c492dc52a98f6f830d1e33ca7456e1
Successfully built mvnc
Installing collected packages: mvnc
  Found existing installation: mvnc 1.12.0.1
    Uninstalling mvnc-1.12.0.1:
      Successfully uninstalled mvnc-1.12.0.1
Successfully installed mvnc-1.12.0.1
NCS Libraries have been installed in /usr/local/lib
NCS Toolkit binaries have been installed in /usr/local/bin
NCS Include files have been installed in /usr/local/include
NCS Python API has been installed in /opt/movidius, and PYTHONPATH environment variable updated
Updating udev rules...
Adding user 'root' to 'users' group
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 NCSDK.
Please provide feedback in our support forum if you encountered difficulties.

ということで、めでたくNCSDKがインストールできました。

3. Test installation by running built-in examples

あとは、ExampleをダウンロードしてMakeするだけ。。。のはず。。。
しかーし、結構エラー出てます。しかも、5時間位延々かかりました。
はっきり言って、NCSDK再インストール始めちゃったかと思いました。
途中、なぜかOpenCVのインストールが続きます。。。なんだろ??
そして、以下がそのほぼ最後のところ、。。

bvlc_googlenet.caff 100%[===================>]  51.05M  1.85MB/s    in 47s     
2018-06-02 19:02:52 (1.09 MB/s) - `./bvlc_googlenet.caffemodel' へ保存完了 [53533754/53533754]
making compile
mvNCCompile -w bvlc_googlenet.caffemodel -s 12 deploy.prototxt
mvNCCompile v02.00, Copyright @ Movidius Ltd 2016

Error importing caffe
make[4]: ディレクトリ '/home/pi/workspace/ncsdk/examples/caffe/GoogLeNet' から出ます
cp: '../../caffe/GoogLeNet/graph' を stat できません: そのようなファイルやディレクトリはありません
Makefile:9: ターゲット 'googlenet' のレシピで失敗しました
make[3]: *** [googlenet] エラー 1
make[3]: ディレクトリ '/home/pi/workspace/ncsdk/examples/apps/multistick_cpp' から出ます
Makefile:12: ターゲット 'multistick_cpp/.' のレシピで失敗しました
make[2]: *** [multistick_cpp/.] エラー 2
make[2]: ディレクトリ '/home/pi/workspace/ncsdk/examples/apps' から出ます
Makefile:12: ターゲット 'apps/.' のレシピで失敗しました
make[1]: *** [apps/.] エラー 2
make[1]: ディレクトリ '/home/pi/workspace/ncsdk/examples' から出ます
Makefile:57: ターゲット 'examples' のレシピで失敗しました
make: *** [examples] エラー 2

つまり、Error importing caffeがつらいところ、一体何をインストールしていたんだ??と疑いたくなりました。

この件に関しては、以下のとおり、バグレポートの山。。。
※解決策は最後に。。。
Caffe Import Error with fresh installed SDK (help) - NCSDK 1.09.00.04 - x86_64 - Ubuntu 16.04

とはいっても、本体は無事にインストールできているはずなので、何か動かないかと探してみると、以下のとおり、定番HelloWorld。。。

pi@raspberrypi:~/workspace/ncsdk/examples/apps/hello_ncs_py $ python3 hello_ncs.py
Hello NCS! Device opened normally.
Goodbye NCS! Device closed normally.
NCS device working.

NCSデバイスがちゃんと使えたというメッセージ!

そして次に、Caffe以外のものということで、TensorflowのExampleにあった、InceptionV3を動かして見ました。
nps_electric_guitar.png

tensorflow/inception_v3 $ python3 run.py
Number of categories: 1001
Start download to NCS...
*******************************************************************************
inception-v3 on NCS
*******************************************************************************
547 electric guitar 0.98828
403 acoustic guitar 0.0077209
715 pick, plectrum, plectron 0.0015087
421 banjo 0.00092602
820 stage 0.00065947
*******************************************************************************
Finished

ちゃんと、高精度で識別できました。
猫に変えてやってみました。
cat.jpg

tensorflow/inception_v3/run.py =
Number of categories: 1001
Start download to NCS...
*******************************************************************************
inception-v3 on NCS
*******************************************************************************
282 tabby, tabby cat 0.58984
283 tiger cat 0.21362
286 Egyptian cat 0.045288
553 feather boa, boa 0.0065536
841 swab, swob, mop 0.0051422
*******************************************************************************
Finished

これも見事に猫を検出しています。これは使えそうです。
※ただし、このコードはインテル社のcopyrightだそうです。利用も改変もできないようです。

以下は、InceptionV1の上記のギターの結果ですが、なんかおかしいです。
※たぶん、Categoryが学習時と変わっちゃってるような気がします。
※これCategoryは中身見るとImageNetみたいです。

tensorflow/inception_v1/run.py =
Number of categories: 1001
Start download to NCS...
*******************************************************************************
inception-v1 on NCS
*******************************************************************************
513 corkscrew, bottle screw 0.94971
819 spotlight, spot 0.050354
1000 toilet tissue, toilet paper, bathroom tissue 0.0
334 hamster 0.0
329 sea urchin 0.0
*******************************************************************************
Finished

(2)Caffeのインストール:上記のバグの山の解決策!

sudo apt install caffe-cpu

【参考】
Ubuntu Installation

Caffeのexampleがすべて、import caffeでエラーなので、インストールしてみました。
その結果、見事にGoogLeNetが動きました。

caffe/GoogLeNet $ python3 run.py
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 865724 bytes...
Successfully sent 865724 bytes of data in 134.612878 ms (6.133282 MB/s)
Boot successful, device address 1.4
Found Address: 1.4 - VID/PID 03e7:f63b
done
Booted 1.4 -> 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

無事に精度よく認識できました!

まとめ

・今回はStretchを直接インストールしました
・RasPiにMovidius NCSをインストールして、物体認識アプリを動かしました

次回は、さらなるExampleを動かしつつ、物体検出アプリなどをMovidiusにインストールして利用したいと思います。

4
3
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
4
3