雜亂大全38-OpenVINO (上)-pi4+ncs2

  • 前言:介紹樹莓派+NCS2跑OpenVINO
tags: 六角學院

主題:雜亂大全38-OpenVINO (上)-pi4+ncs2

本篇重點:

  • 樹莓派+NCS2跑OpenVINO

官方

OpenVINO-工具
https://docs.openvinotoolkit.org/latest/index.html

Github

https://github.com/openvinotoolkit/openvino


使用不同版本語法
git clone -b ‘tag版本’ ‘網址’
或是下載後使用git checkout ‘版本’

參考-版本控制


簡介

整合OpenCV、OpenCL、OpenVX+硬體上的加速優化,
支持CPU、GPU、NCS、VPU、FPGA上運行,
但尚未支援AMD CPU,
提供多個pre-train的視覺分類、偵測、分割模型。
支持主流的框架
如Caffe, TensorFlow, MXNet, Kaldi pytorch(ONNX)

流程

  • 要先找到要demo的模型
  • 再找open model zoo的xml+bin
  • 依照官方說明,結合demo的類神經網路與pre-train的XML
  • 但有很多版本問題,我的測試以2019_R3版+2020.1版為主

先在pi4上測試

  • 提醒,一定要使用NCS2,不然不能跑
  • 且有許多版本問題
  • 有發問intel公司,回覆:的確許多內容目前還不相容
  • 請參見建誠學長的統整理:
  • https://hackmd.io/wFgT_RRuSmuNGthiNSo8OQ

pi4實作

  • 一定要有NCS2,不然不能運作!

範例實作

  • 參考資料

  • https://zhuanlan.zhihu.com/p/268357796

  • 先下載並新建資料夾(我選用2020.1版本)

    1
    2
    3
    4
    5
    6
    cd ~/Downloads/
    sudo wget https://download.01.org/opencv/2020/openvinotoolkit/2020.1/l_openvino_toolkit_runtime_raspbian_p_2020.1.023.tgz
    # 創建資料夾
    sudo mkdir -p /opt/intel/openvino
    # 解壓縮文件
    sudo tar -xf l_openvino_toolkit_runtime_raspbian_p_2020.1.023.tgz --strip 1 -C /opt/intel/openvino
  • 安裝cmake (一定要安裝)

    1
    sudo apt install cmake
  • 設定環境參數

    1
    2
    3
    source /opt/intel/openvino/bin/setupvars.sh
    # 永久設定環境參數
    echo "source /opt/intel/openvino/bin/setupvars.sh" >> ~/.bashrc

    顯示:

    1
    [setupvars.sh] OpenVINO environment initialized
  • 增添USB規則

    1
    2
    sudo usermod -a -G users "$(whoami)"
    sh /opt/intel/openvino/install_dependencies/install_NCS_udev_rules.sh
  • 重新插入NCS2

  • 建立測試資料夾與下載測試用模型

    1
    2
    3
    cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-march=armv7-a" /opt/intel/openvino/deployment_tools/inference_engine/samples/cpp

    make -j2 object_detection_sample_ssd
  • 下載搭配的XML+BIN檔案 (各版本都不同,我選用2019_R3)

    1
    2
    3
    wget --no-check-certificate https://download.01.org/opencv/2019/open_model_zoo/R3/20190905_163000_models_bin/face-detection-retail-0005/FP16/face-detection-retail-0005.bin

    wget --no-check-certificate https://download.01.org/opencv/2019/open_model_zoo/R3/20190905_163000_models_bin/face-detection-retail-0005/FP16/face-detection-retail-0005.xml
  • 執行程式

    -m 代表.xml 文件(系統會自己去找同名的bin檔)
    -d MYRIAD 代表NCS2;
    -i 代表要測試圖片的路徑

    1
    ./armv7l/Release/object_detection_sample_ssd -m face-detection-retail-0005.xml -d MYRIAD -i ~/Downloads/image
  • 執行前

  • 執行過程

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    pi@pi:~/Downloads/openvino/build $ ./armv7l/Release/object_detection_sample_ssd -m face-detection-retail-0005.xml -d MYRIAD -i ~/Downloads/imagee
    [ INFO ] InferenceEngine:
    API version ............ 2.1
    Build .................. custom_releases/2020/1_d349c3ba4a2508be72f413fa4dee92cc0e4bc0e1
    Description ....... API
    Parsing input parameters
    [ INFO ] Files were added: 1
    [ INFO ] /home/pi/Downloads/imagee/003.jpg
    [ INFO ] Loading Inference Engine
    [ INFO ] Device info:
    MYRIAD
    myriadPlugin version ......... 2.1
    Build ........... 37988
    [ INFO ] Loading network files:
    face-detection-retail-0005.xml
    face-detection-retail-0005.bin
    [ 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 (1280, 852) to (300, 300)
    [ INFO ] Batch size is 1
    [ INFO ] Start inference
    [ INFO ] Processing output blobs
    [0,1] element, prob = 0.999512 (247,276)-(369,421) batch id : 0 WILL BE PRINTED!
    [1,1] element, prob = 0.999023 (410,27)-(506,145) batch id : 0 WILL BE PRINTED!
    [2,1] element, prob = 0.99707 (607,326)-(731,465) batch id : 0 WILL BE PRINTED!
    [3,1] element, prob = 0.994141 (721,1)-(828,91) batch id : 0 WILL BE PRINTED!
    [4,1] element, prob = 0.968262 (910,298)-(1021,421) batch id : 0 WILL BE PRINTED!
    [5,1] element, prob = 0.949219 (1037,55)-(1147,181) batch id : 0 WILL BE PRINTED!
    [6,1] element, prob = 0.914062 (78,20)-(180,143) batch id : 0 WILL BE PRINTED!
    [7,1] element, prob = 0.09375 (1234,300)-(1281,406) 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
    pi@pi:~/Downloads/openvino/build $
  • 執行後

  • 測試迭代1000次

  • 建立程序

    1
    make -j2 benchmark_app
  • 迭代參數 -niter (要迭代的次數)

    1
    ./armv7l/Release/benchmark_app -i ~/Downloads/image -m face-detection-retail-0005.xml -pc -d MYRIAD -niter 1000
  • 迭代過程與結果-節錄結果

1
2
3
4
5
6
7
8
9
10
Total time: 39620    microseconds

Full device name: Intel Movidius Myriad X VPU

Count: 1000 iterations
Duration: 21974.01 ms
Latency: 87.67 ms
Throughput: 45.51 FPS
Peak Virtual Memory (VmPeak) Size, kBytes: 108124
Peak Resident Memory (VmHWM) Size, kBytes: 35804

補充:

Pi目前支援的部分很少,幾乎沒有支援即時影像
參考官方回文:
https://community.intel.com/t5/Intel-Distribution-of-OpenVINO/InferenceEngineException-on-raspberrypi-Product-of-output-shape/td-p/1184671#


補充資料

後記:

下一篇將介紹以windows執行的結果