Install the OpenVINO™ Toolkit for Raspbian* OS from a Docker* Image

Documentation

Install & Setup

000055220

09/02/2020

The Intel® Distribution of OpenVINO™ toolkit quickly deploys applications and solutions that emulate human vision. The toolkit extends computer vision (CV) workloads across Intel® hardware based on Convolutional Neural Networks (CNN), which maximizes performance. The Intel® Distribution of OpenVINO™ Toolkit also includes the Intel® Deep Learning Deployment Toolkit.

This guide provides users with steps for creating a Docker* image to install the OpenVINO™ Toolkit for Raspbian* OS.

System Requirements

Target Operating System

  • Raspbian* Stretch, 32-bit
  • Raspbian* Buster, 32-bit

Host Operating Systems

  • Raspbian* Stretch, 32-bit
  • Raspbian* Buster, 32-bit

Hardware

  • Raspberry Pi* board with ARM* ARMv7-A CPU architecture. Check that uname -m returns armv7l.
    • Raspberry Pi* 3 Model B+
    • Raspberry Pi* 4 Model B
  • One of Intel® Movidius™ Visual Processing Units (VPU):
    • Intel® Movidius™ Neural Compute Stick
    • Intel® Neural Compute Stick 2

Software

Note

Use the automated convenience scripts to install Docker*, as this is currently the only way to install this toolkit for Raspbian*. Find more information.

Building a Docker* Image for Intel® Movidius™ Neural Compute Stick or Intel® Neural Compute Stick 2

Build Image

To build a Docker* image, you'll need to create a Dockerfile that contains the defined variables and commands required to create an OpenVINO™ Toolkit installation image.

Create your Dockerfile using the following example as a template.

  1. Create or go to a directory where you will create your Docker* image. This document creates a ~/docker directory.

    mkdir ~/docker && cd ~/docker

  2. Download the Dockerfile template (ZIP) from this guide or create your own Dockerfile using the contents of the template below.

    vi Dockerfile

    FROM balenalib/rpi-raspbian:latest

    ARG DOWNLOAD_LINK=https://download.01.org/opencv/2020/openvinotoolkit/2020.3/l_openvino_toolkit_runtime_raspbian_p_2020.3.220.tgz
    ARG INSTALL_DIR=/opt/intel/openvino 
    ARG BIN_FILE=https://download.01.org/opencv/2019/open_model_zoo/R3/20190905_163000_models_bin/person-vehicle-bike-detection-crossroad-0078/FP16/person-vehicle-bike-detection-crossroad-0078.bin
    ARG WEIGHTS_FILE=https://download.01.org/opencv/2019/open_model_zoo/R3/20190905_163000_models_bin/person-vehicle-bike-detection-crossroad-0078/FP16/person-vehicle-bike-detection-crossroad-0078.xml
    ARG IMAGE_FILE=https://cdn.pixabay.com/photo/2018/07/06/00/33/person-3519503_960_720.jpg

    RUN apt-get update && apt-get install -y --no-install-recommends \
       apt-utils \
       automake \
       cmake \
       cpio \
       gcc \
       g++ \
       libatlas-base-dev \
       libstdc++6 \
       libtool \
       libusb-1.0.0-dev \
       lsb-release \
       make \
       python3-pip \
       python3-numpy \
       python3-scipy \
       libgtk-3-0 \
       pkg-config \
       libavcodec-dev \
       libavformat-dev \
       libswscale-dev \
       sudo \
       udev \
       unzip \
       vim \
       wget && \
    rm -rf /var/lib/apt/lists/*
    RUN mkdir -p $INSTALL_DIR && cd $INSTALL_DIR && \
       wget -c $DOWNLOAD_LINK && \
       tar xf l_openvino_toolkit_runtime_raspbian_p*.tgz --strip 1 -C $INSTALL_DIR
    # add USB rules
    RUN sudo usermod -a -G users "$(whoami)" && \
       /bin/bash -c "source $INSTALL_DIR/bin/setupvars.sh && \
       sh $INSTALL_DIR/install_dependencies/install_NCS_udev_rules.sh"
    # build Object Detection sample
    RUN echo "source /opt/intel/openvino/bin/setupvars.sh" >> ~/.bashrc && \
       mkdir /root/Downloads && \
       cd $INSTALL_DIR/deployment_tools/inference_engine/samples/c/ && \
       /bin/bash -c "source $INSTALL_DIR/bin/setupvars.sh && \
       ./build_samples.sh && \
       wget --no-check-certificate $BIN_FILE -O /root/Downloads/person-vehicle-bike-detection-crossroad-0078.bin && \
       wget --no-check-certificate $WEIGHTS_FILE -O /root/Downloads/person-vehicle-bike-detection-crossroad-0078.xml && \
       wget --no-check-certificate $IMAGE_FILE -O /root/Downloads/walk.jpg "
    RUN echo "import cv2 as cv\n\
    # Load the model.\n\
    net = cv.dnn.readNet('person-vehicle-bike-detection-crossroad-0078.xml',\
    'person-vehicle-bike-detection-crossroad-0078.bin')\n\
    # Specify target device.\n\
    net.setPreferableTarget(cv.dnn.DNN_TARGET_MYRIAD)\n\
    # Read an image.\n\
    frame = cv.imread('walk.jpg')\n\
    if frame is None:\n\
       raise Exception('Image not found!')\n\
    # Prepare input blob and perform an inference.\n\
    blob = cv.dnn.blobFromImage(frame, size=(1024, 1024), ddepth=cv.CV_8U)\n\
    net.setInput(blob)\n\
    out = net.forward()\n\
    # Draw detected faces on the frame.\n\
    for detection in out.reshape(-1, 7):\n\
       confidence = float(detection[2])\n\
       xmin = int(detection[3] * frame.shape[1])\n\
       ymin = int(detection[4] * frame.shape[0])\n\
       xmax = int(detection[5] * frame.shape[1])\n\
       ymax = int(detection[6] * frame.shape[0])\n\
       if confidence > 0.5:\n\
          cv.rectangle(frame, (xmin, ymin), (xmax, ymax), color=(0, 255, 0))\n\
    # Save the frame to an image file.\n\
    cv.imwrite('out.png', frame)\n\
    print('Detection results in out.png')" >> /root/Downloads/openvino_fd_myriad.py

     
    Note

    You will need to replace the direct link to the OpenVINO™ Toolkit package in the DOWNLOAD_LINK variable in the template above with that of the latest version. You can copy the link of the OpenVINO Toolkit for Raspbian* OS package from the Intel® Open Source Technology Center . Select the latest version available, right click on the URL and press Copy link address.

  3. To build a Docker* image for Intel® Movidius™ Neural Compute Stick or Intel® Neural Compute Stick 2, run the following command:

    docker build . -t <image_name>

    (i.e. docker build . -t openvino-rpi)

Run and Test a Docker* Image

Known limitations:

  • The Intel® Movidius™ Neural Compute Stick device changes its VendorID and DeviceID during execution and each time looks for a host system as a brand new device. This means it cannot be mounted as usual.
  • UDEV events aren't forwarded to the container by default, and so it isn't aware of device reconnection.
  • Only one device is supported per host.

Run Object Detection Sample

The application outputs an image (out_0.bmp) with any detected person enclosed in rectangles.

  1. Use the following option to run the image on an Intel® Movidius™ Neural Compute Stick or Intel® Neural Compute Stick 2. To run this container in interactive and privileged mode, enable Docker network configuration as host, then mount all devices to the container:

    docker run -it --privileged -v /dev:/dev --network=host <image_name>

    (i.e. docker run -it --privileged -v /dev:/dev --network=host openvino-rpi)

  2. Use the following commands to run Object Detection Sample. Go to the build samples directory:

    cd /root/inference_engine_c_samples_build/armv7l/Release/

  3. Run the sample with specifications for the model and a path to the input image:

    ./object_detection_sample_ssd_c -m ~/Downloads/person-vehicle-bike-detection-crossroad-0078.xml -i ~/Downloads/walk.jpg -d MYRIAD

Run Inference of Face Detection Model Using OpenCV* API

  1. Navigate to the directory where the openvino_fd_myriad.py script is located:

    cd /root/Downloads

  2. Run the script:

    python3 openvino_fd_myriad.py

In this script, OpenCV* loads the person-vehicle-bike detection model from the Intermediate Representation (IR) format and an image. Then it runs the inference and saves the image with the detection results as out.png.

This completes the installation procedure for the OpenVINO™ Toolkit for Raspbian* from a Docker* Image.

Related Topics