私的AI研究会 > OMZonRaspi

Raspberry Pi4 に OpenVINO™ Toolkit「2021.3」をインストール

 OpenVINO™ Toolkit「2021.3」を Raspberry Pi4 にインストールする手順を再確認する。サイトの説明がバージョンの古いものが多くなってきているのでオフィシャルサイト に従って進める。

※ 最終更新:2021/06/16 

事前準備

OpenVINO™ ツールキットのインストール

OpenVINO™ ツールキットのダウンロード

2021年04月04日現在、OpenVINO™ ツールキットの最新バージョンは 2021.3

● VNCビューアなどで、Raspberry Pi 上のブラウザでオフィシャルサイトのダウンロードページから下記のファイルをダウンロードする。
● ファイル名:l_openvino_toolkit_runtime_raspbian_p_2021.3.394.tgz
 ※ファイルは「~/Download」ディレクトリに配置される。

pi@raspberrypi:~ $ cd ~/Downloads
pi@raspberrypi:~/Downloads $ ls
l_openvino_toolkit_runtime_raspbian_p_2021.3.394.tgz

OpenVINO™ 本体のインストール

  1. OpenVINO™ ツールキットを展開するフォルダを作成する。
    pi@raspberrypi:~/Downloads $ sudo mkdir -p /opt/intel/openvino
    pi@raspberrypi:~/Downloads $ ls /opt
    Wolfram  intel  minecraft-pi  pigpio  vc
    pi@raspberrypi:~/Downloads $ ls /opt/intel
    openvino
  2. ダウンロードしたファイルを「/opt/intel/openvino」に展開する。
    pi@raspberrypi:~/Downloads $ sudo tar -xf l_openvino_toolkit_runtime_raspbian_p_2021.3.394.tgz --strip 1 -C /opt/intel/openvino
    pi@raspberrypi:~/Downloads $ ls /opt/intel/openvino
    bin  deployment_tools  documentation  inference_engine  install_dependencies  licensing  opencv  python
  3. サンプルコードをビルドするために「CMake」をインストールする。
    pi@raspberrypi:~/Downloads $ sudo apt update
    pi@raspberrypi:~/Downloads $ sudo apt install cmake
    パッケージリストを読み込んでいます... 完了
    依存関係ツリーを作成しています                
    状態情報を読み取っています... 完了 
    以下の追加パッケージがインストールされます:
      cmake-data libjsoncpp1 librhash0
        :
    この操作後に追加で 22.3 MB のディスク容量が消費されます。
    続行しますか? [Y/n] y
    取得:1 http://ftp.jaist.ac.jp/raspbian buster/main armhf libjsoncpp1 armhf 1.7.4-3 [66.2 kB]
    取得:2 http://ftp.jaist.ac.jp/raspbian buster/main armhf librhash0 armhf 1.3.8-1 [132 kB]
        :
  4. 環境変数の設定
    setupvars.shスクリプトを実行することにより OpenVINO™ ツールキットが動作するように環境を整える。
    サイトの説明とインストールディレクトリが違うようなので変更しておく。「openvino」→「openvino_2021」
    pi@raspberrypi-mas:~/Downloads $ source /opt/intel/openvino_2021/bin/setupvars.sh
    -bash: /opt/intel/openvino_2021/bin/setupvars.sh: そのようなファイルやディレクトリはありません
    pi@raspberrypi-mas:~/Downloads $ ls /opt/intel
    openvino
    pi@raspberrypi-mas:~/Downloads $ sudo mv /opt/intel/openvino /opt/intel/openvino_2021
    pi@raspberrypi-mas:~/Downloads $ ls /opt/intel
    openvino_2021
    pi@raspberrypi-mas:~/Downloads $ source /opt/intel/openvino_2021/bin/setupvars.sh
    [setupvars.sh] OpenVINO environment initialized
    実行して[setupvars.sh] OpenVINO environment initializedと表示されればOK。
  5. 起動時に自動でコマンド実行するように設定する。
    pi@raspberrypi:~/Downloads $ echo "source /opt/intel/openvino_2021/bin/setupvars.sh" >> ~/.bashrc
    ターミナルソフトを終了して、再度開いて[setupvars.sh] OpenVINO environment initializedと表示されればOK。
  6. 「Neural Compute Stick」を使って OpenVINO™ を実行できるようにスクリプトを実行する。
    pi@raspberrypi:~ $ sh /opt/intel/openvino_2021/install_dependencies/install_NCS_udev_rules.sh
    Updating udev rules...
    Udev rules have been successfully installed.
    udev rules installedと表示されればOK。
  7. 「Intel© Neural Compute Stick 2」を差し込む。
    以上でオブジェクト検出サンプルをコンパイルして実行し、推論エンジンのインストールを確認する準備が整った。

サンプルのビルドと実行

  1. ユーザーのホームディレクトリに「build」フォルダを作成して移動する。
    pi@raspberrypi:~ $ mkdir build && cd build
  2. オブジェクト検出サンプルをビルドする。(前半)
    pi@raspberrypi:~/build $ cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-march=armv7-a" /opt/intel/openvino_2021/deployment_tools/inference_engine/samples/cpp
    -- The C compiler identification is GNU 8.3.0
    -- The CXX compiler identification is GNU 8.3.0
    -- Check for working C compiler: /usr/bin/cc
    -- Check for working C compiler: /usr/bin/cc -- works
    -- Detecting C compiler ABI info
    -- Detecting C compiler ABI info - done
    -- Detecting C compile features
    -- Detecting C compile features - done
    -- Check for working CXX compiler: /usr/bin/c++
    -- Check for working CXX compiler: /usr/bin/c++ -- works
    -- Detecting CXX compiler ABI info
    -- Detecting CXX compiler ABI info - done
    -- Detecting CXX compile features
    -- Detecting CXX compile features - done
    -- Looking for C++ include unistd.h
    -- Looking for C++ include unistd.h - found
    -- Looking for C++ include stdint.h
    -- Looking for C++ include stdint.h - found
    -- Looking for C++ include sys/types.h
    -- Looking for C++ include sys/types.h - found
    -- Looking for C++ include fnmatch.h
    -- Looking for C++ include fnmatch.h - found
    -- Looking for strtoll
    -- Looking for strtoll - found
    -- Found InferenceEngine: /opt/intel/openvino_2021/deployment_tools/inference_engine/lib/armv7l/libinference_engine.so (Required is at least version "2.1") 
    -- Configuring done
    -- Generating done
    -- Build files have been written to: /home/pi/build
  3. 続けてサンプルをビルドするためのコマンド。(後半)
    pi@raspberrypi:~/build $ make -j2 object_detection_sample_ssd
    Scanning dependencies of target format_reader
    Scanning dependencies of target gflags_nothreads_static
    [  9%] Building CXX object thirdparty/gflags/CMakeFiles/gflags_nothreads_static.dir/src/gflags.cc.o
    [ 18%] Building CXX object common/format_reader/CMakeFiles/format_reader.dir/MnistUbyte.cpp.o
    [ 27%] Building CXX object common/format_reader/CMakeFiles/format_reader.dir/bmp.cpp.o
    [ 36%] Building CXX object common/format_reader/CMakeFiles/format_reader.dir/format_reader.cpp.o
    [ 45%] Building CXX object thirdparty/gflags/CMakeFiles/gflags_nothreads_static.dir/src/gflags_reporting.cc.o
    [ 54%] Building CXX object common/format_reader/CMakeFiles/format_reader.dir/opencv_wraper.cpp.o
    [ 63%] Building CXX object thirdparty/gflags/CMakeFiles/gflags_nothreads_static.dir/src/gflags_completions.cc.o
    [ 72%] Linking CXX static library ../../armv7l/Release/lib/libgflags_nothreads.a
    [ 72%] Built target gflags_nothreads_static
    [ 81%] Linking CXX shared library ../../armv7l/Release/lib/libformat_reader.so
    [ 81%] Built target format_reader
    Scanning dependencies of target object_detection_sample_ssd
    [ 90%] Building CXX object object_detection_sample_ssd/CMakeFiles/object_detection_sample_ssd.dir/main.cpp.o
    [100%] Linking CXX executable ../armv7l/Release/object_detection_sample_ssd
    [100%] Built target object_detection_sample_ssd
  4. 学習済みファイル をダウンロードする。
    pi@raspberrypi:~/build $ git clone --depth 1 https://github.com/openvinotoolkit/open_model_zoo
    Cloning into 'open_model_zoo'...
    remote: Enumerating objects: 2754, done.
    remote: Counting objects: 100% (2754/2754), done.
    remote: Compressing objects: 100% (2292/2292), done.
    remote: Total 2754 (delta 779), reused 1173 (delta 357), pack-reused 0
    Receiving objects: 100% (2754/2754), 127.57 MiB | 2.35 MiB/s, done.
    Resolving deltas: 100% (779/779), done.
    Checking out files: 100% (2248/2248), done.
    pi@raspberrypi:~/build $ cd open_model_zoo/tools/downloader
    pi@raspberrypi:~/build/open_model_zoo/tools/downloader $ python3 -m pip install -r requirements.in
    Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
    Collecting pyyaml (from -r requirements.in (line 1))
      Downloading https://files.pythonhosted.org/packages/a0/a4/d63f2d7597e1a4b55aa3b4d6c5b029991d3b824b5bd331af8d4ab1ed687d/PyYAML-5.4.1.tar.gz (175kB)
        100% |████████████████████████████████| 184kB 1.1MB/s 
      Installing build dependencies ... done
    Requirement already satisfied: requests in /usr/lib/python3/dist-packages (from -r requirements.in (line 2)) (2.21.0)
    Building wheels for collected packages: pyyaml
      Running setup.py bdist_wheel for pyyaml ... done
      Stored in directory: /home/pi/.cache/pip/wheels/2a/d4/92/cf299bdf4162957ca8126b46e913e29f76a4f17ca762c45028
    Successfully built pyyaml
    Installing collected packages: pyyaml
    Successfully installed pyyaml-5.4.1
    pi@raspberrypi:~/build/open_model_zoo/tools/downloader $ python3 downloader.py --name face-detection-adas-0001
    ################|| Downloading face-detection-adas-0001 ||################
    
    ========== Downloading /home/pi/build/open_model_zoo/tools/downloader/intel/face-detection-adas-0001/FP32/face-detection-adas-0001.xml
    ... 100%, 226 KB, 275 KB/s, 0 seconds passed
    
    ========== Downloading /home/pi/build/open_model_zoo/tools/downloader/intel/face-detection-adas-0001/FP32/face-detection-adas-0001.bin
    ... 100%, 4113 KB, 1757 KB/s, 2 seconds passed
    
    ========== Downloading /home/pi/build/open_model_zoo/tools/downloader/intel/face-detection-adas-0001/FP16/face-detection-adas-0001.xml
    ... 100%, 226 KB, 270 KB/s, 0 seconds passed
    
    ========== Downloading /home/pi/build/open_model_zoo/tools/downloader/intel/face-detection-adas-0001/FP16/face-detection-adas-0001.bin
    ... 100%, 2056 KB, 1202 KB/s, 1 seconds passed
    
    ========== Downloading /home/pi/build/open_model_zoo/tools/downloader/intel/face-detection-adas-0001/FP16-INT8/face-detection-adas-0001.xml
    ... 100%, 502 KB, 483 KB/s, 1 seconds passed
    
    ========== Downloading /home/pi/build/open_model_zoo/tools/downloader/intel/face-detection-adas-0001/FP16-INT8/face-detection-adas-0001.bin
    ... 100%, 1074 KB, 814 KB/s, 1 seconds passed
  5. ダウンロードした学習済みモデルファイルを実行ファイルのある場所へコピーする。
    $ cd~/build
    pi@raspberrypi:~/build $ cp open_model_zoo/tools/downloader/intel/face-detection-adas-0001/FP16-INT8/face-detection-adas-0001.bin ./
    pi@raspberrypi:~/build $ cp open_model_zoo/tools/downloader/intel/face-detection-adas-0001/FP16-INT8/face-detection-adas-0001.xml ./
    pi@raspberrypi:~/build $ ls
    CMakeCache.txt  benchmark_app                face-detection-adas-0001.bin     hello_query_device               open_model_zoo
    CMakeFiles      classification_sample_async  face-detection-adas-0001.xml     hello_reshape_ssd                speech_sample
    Makefile        cmake_install.cmake          hello_classification             ngraph_function_creation_sample  style_transfer_sample
    armv7l          common                       hello_nv12_input_classification  object_detection_sample_ssd      thirdparty
  6. ディープラーニング推論する画像を用意し、「~/Images/」ディレクトリに「input.jpg」という名前で保存する。
  7. ディープラーニング推論を実行する。
    pi@raspberrypi-mas:~/build $ ./armv7l/Release/object_detection_sample_ssd -m face-detection-adas-0001.xml -d MYRIAD -i ~/Images/input.jpg
    [ INFO ] InferenceEngine: 
        API version ............ 2.1
        Build .................. 2021.3.0-2787-60059f2c755-releases/2021/3
        Description ....... API
    Parsing input parameters
    [ INFO ] Files were added: 1
    [ INFO ]     /home/pi/Images/input.jpg
    [ INFO ] Loading Inference Engine
    [ INFO ] Device info: 
        MYRIAD
        myriadPlugin version ......... 2.1
        Build ........... 2021.3.0-2787-60059f2c755-releases/2021/3
    [ INFO ] Loading network files:
        face-detection-adas-0001.xml
    [ INFO ] Preparing input blobs
    [ INFO ] Batch size is 1
    [ INFO ] Preparing output blobs
    [ INFO ] Loading model to the device
    [ ERROR ] Failed to compile layer "conv1/fq_input_0": unsupported layer type "FakeQuantize"
    エラーとなるので学習済みモデルを 2021.2 版のものを使う。
    pi@raspberrypi-mas:~/build $ ./armv7l/Release/object_detection_sample_ssd -m face-detection-adas-0001.xml -d MYRIAD -i ~/Images/input.jpg
    [ INFO ] InferenceEngine: 
        API version ............ 2.1
        Build .................. 2021.3.0-2787-60059f2c755-releases/2021/3
        Description ....... API
    Parsing input parameters
    [ INFO ] Files were added: 1
    [ INFO ]     /home/pi/Images/input.jpg
    [ INFO ] Loading Inference Engine
    [ INFO ] Device info: 
        MYRIAD
        myriadPlugin version ......... 2.1
        Build ........... 2021.3.0-2787-60059f2c755-releases/2021/3
    [ INFO ] Loading network files:
        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 (1440, 1048) to (672, 384)
    [ INFO ] Batch size is 1
    [ INFO ] Start inference
    [ INFO ] Processing output blobs
    [0,1] element, prob = 1    (615,122)-(827,377) batch id : 0 WILL BE PRINTED!
    [1,1] element, prob = 1    (875,378)-(1068,628) batch id : 0 WILL BE PRINTED!
    [2,1] element, prob = 0.0756836    (1227,2)-(1338,139) batch id : 0
    [3,1] element, prob = 0.0756836    (1312,1)-(1397,100) batch id : 0
    [4,1] element, prob = 0.0683594    (1337,6)-(1435,113) batch id : 0
    [5,1] element, prob = 0.0629883    (1231,21)-(1290,96) batch id : 0
        :
        :
    [86,1] element, prob = 0.0366211    (1120,69)-(1222,230) batch id : 0
    [87,1] element, prob = 0.0356445    (230,19)-(281,92) batch id : 0
    [88,1] element, prob = 0.0356445    (1161,77)-(1203,134) batch id : 0
    [89,1] element, prob = 0.0356445    (1198,77)-(1238,134) batch id : 0
    [90,1] element, prob = 0.0356445    (1117,116)-(1172,196) batch id : 0
    [91,1] element, prob = 0.0356445    (1158,123)-(1199,186) batch id : 0
    [92,1] element, prob = 0.0356445    (273,165)-(317,239) batch id : 0
    [93,1] element, prob = 0.0356445    (294,203)-(344,288) 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
  8. Raspbian* OS 用の OpenVINO™ ツールキットのインストール完了。

付属サンプルプログラムの実行

「Neural Compute Application Zoo」をインストール

Raspberry Pi 上のアプリケーションをホームディレクトリ(~/)にコピー

※ この環境では結果の動画保存は「2021.2」版と同様に保存ファイルが作成できない。。

  1. NCS2 を利用する作成したソフトウェアは CPU 環境と同じように動作する。
  2. デバイスは NCS2 を表す「MYRIAD」とする。
  3. OpenVINO™ Toolkit インストールディレクトリ
    INTEL_OPENVINO_DIR=/opt/intel/openvino_2021

OpenVINO™ ツールキット(2021.3) に含まれる OpenCV のバージョン

 

更新履歴

参考資料

 

Last-modified: 2021-06-16 (水) 19:18:58