Apple Silicon M1: OpenVINO-2021.3, OpenCV-4.5.2-openvino

Introduction



2021-03-26 시점의 내용.

Apple Silicon M1로 빌드하자. OpenVINO도 Neural Compute Stick 2라면 움직입니다.



환경


  • Apple Silicon (M1) MacBook Air
  • Intel Compute Stick 2 (NCS2)
  • OpenVINO 2021.3 (No support CPU:arm)
  • OpenCV 4.5.3-openvino

  • MacPorts
  • sudo port install cmake gflags autoconf automake libtool libusb git-lfs


  • Miniforge3
  • conda install numpy matplotlib cython pandas scipy scikit-learn


  • build OpenCV 4.5.2-openvino



    소스 트리


    git clone --depth 1 -b 4.5.2-openvino https://github.com/opencv/opencv.git opencv-4.5.2-openvino
    

    build



    Install dir/opt/intel/openvino/opencv. Same as OpenVINO Distribution.
    mkdir opencv-4.5.2-openvino/build
    cd opencv-4.5.2-openvino/build
    
    cmake \
        -DCMAKE_INSTALL_PREFIX=/opt/intel/openvino/opencv \
        -DCMAKE_BUILD_TYPE=Release \
        -DWITH_INF_ENGINE=ON \
        -DENABLE_CXX11=ON \
        -DWITH_TBB=ON \
        -DPYTHON3_EXECUTABLE=$HOME/miniforge3/bin/python3.9 \
        -DPYTHON3_LIBRARY=$HOME/miniforge3/lib/libpython3.9.dylib \
        -DPYTHON3_INCLUDE_DIR=$HOME/miniforge3/include/python3.9 ..
    
    make -j 4
    sudo make install
    

    build OpenVINO 2021.3



    소스 트리


    git clone -b 2021.2 https://github.com/openvinotoolkit/openvino.git openvino-2021.3
    cd openvino-2021.3
    git submodule update --init --recursive
    

    build



    Install dir/opt/intel/openvino. Same as OpenVINO Distribution.
    mkdir openvino-2021.3/build
    cd openvino-2021.3/build
    
    cmake \
        -DCMAKE_INSTALL_PREFIX=/opt/intel/openvino \
        -DCMAKE_BUILD_TYPE=Release \
        -DENABLE_PYTHON=ON \
        -DPYTHON_EXECUTABLE=$HOME/miniforge3/bin/python3.9 \
        -DPYTHON_LIBRARY=$HOME/miniforge3/lib/libpython3.9.dylib \
        -DPYTHON_INCLUDE_DIR=$HOME/miniforge3/include/python3.9 ..
    
    make -j 4
    sudo make install
    

    patch this.
    *** setupvars.sh.orig   2020-12-17 12:28:59.000000000 +0900
    --- setupvars.sh    2020-12-17 12:29:34.000000000 +0900
    ***************
    *** 18,23 ****
    --- 18,24 ----
      BASE_DIR="$( dirname "$SCRIPT_DIR" )"
    
      INSTALLDIR="${BASE_DIR}"
    + INSTALLDIR=/opt/intel/openvino
    

    environment valiable
    source /opt/intel/openvino/bin/setupvars.sh
    export ngraph_DIR=/opt/intel/openvino/deployment_tools/ngraph/cmake
    export OpenCV_DIR=/opt/intel/openvino/opencv 
    export PYTHONPATH=$OpenCV_DIR/lib/python3.9/site-packages:$PYTHONPATH
    

    ※ 서로 의존하고 있으므로 OpenCV → OpenVINO → OpenCV에서 빌드&설치하는 것.

    Run with Intel Neural Compurte Stick 2


    python opencv-4.5.2-openvino/samples/python/video_threaded.py
    
    python /opt/arm64/openvino/deployment_tools/inference_engine/samples/python/classification_sample_async/classification_sample_async.py -m alexnet.xml -d MYRIAD -i image.jpg
    
  • OpenCV DNN backend Inference Engine (OpenVINO: Python, C++)

  • Run Success!! 파이썬에서도 작동합니다.

    Reference



    (최소 스텝 밖에 쓰고 있지 않기 때문에) 여기에 써 있는 채로 잘 가지 않거나, 환경을 다소 변경하고 싶은 경우는 이하에 눈을 통하면 할 수 있지 않을까.
  • M1 MacBook에서 개발 환경 구축
  • OpenVINO wiki: BuildingForMacOS

  • TODO


  • CoreML도 시험하고 싶다, , , 하지만. OpenCV ML backend에서 CoreML을 지원하지 않습니까?
  • 좋은 웹페이지 즐겨찾기