Set up Raspberry Pi + movidius neurons calculate stick two generations deep learning

 

Summary

This article built from scratch, from programming Raspberry Pi system begins to finally calculate run rod face detection. This tutorial calculated rods of the second generation, not suitable for the generation of the rod. 
Reference:  https://software.intel.com/en-us/articles/OpenVINO-Install-RaspberryPI

Material Hardware:

1, Raspberry Pi + 3B 
2, Intel Movidius calculating neuron rod 2 Generation 
3, a display, keyboard, mouse, card reader, used to make pie raspberry 16GTF card system disk 
4, raspberry programming systems send a PC ( win10)

step:

1. Download and extract the raspberry pie image

Raspberry Pi system image using the Stretch versions --2018-11-13-raspbian-stretch, lower than the other versions have not tried this may not be feasible 
Download Link:  http://downloads.raspberrypi.org/raspbian_latest 
Reference:  HTTP: / /shumeipai.nxez.com/download#os 
Download and unzip the file img

2, programming mirrors

Insert 16G TF card, formatting, mirroring open programming software Win32DiskImager.exe load the image, download: 
Here Insert Picture Description 
point write, then yes 
Here Insert Picture Description 
Here Insert Picture Description 
programming success. Do not warn tube format, outright cancellation, pull out the TF card 
programming Reference:  http://bbs.eeworld.com.cn/thread-503614-1-1.html?_t=t

3, start raspberry pie

TF card plug raspberry pie, the other monitor, mouse, keyboard plugged in, and then come in raspberry electric 
Here Insert Picture Description 
red and green lights will flash to indicate system starts successfully, and then wait for the desktop display monitor 
Here Insert Picture Description

4, configuration Raspberry Pi

Boot the installation interface configured Raspberry Pi: 
Here Insert Picture Description 
Here Insert Picture Description 
Here Insert Picture Description 
Next, open the Preferences to configure the hardware 
Here Insert Picture Description 
Here Insert Picture Description 
Here Insert Picture Description 
restart, the configuration is complete 
and then change the source, so download speed will stabilize a little bit faster: 
using administrator privileges, execute

      leafpad /etc/apt/sources.list

In the open file, comment out the original contents of the file with #, replace with the following:

      deb http://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbian/ stretch main contrib non-free rpi
deb-src http://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbian/ stretch main contrib non-free rpi

Save and exit. 
With administrator privileges to perform:

      leafpad /etc/apt/sources.list.d/raspi.list

Comment out the original contents of the file with #, replace with the following:

      deb http://mirror.tuna.tsinghua.edu.cn/raspberrypi/ stretch main ui
deb-src http://mirror.tuna.tsinghua.edu.cn/raspberrypi/ stretch main ui

Save and exit. 
Use sudo apt-get update command to update the software source list, and check your edit is correct. 
Completed, replaced by software source Tsinghua University. 
Here Insert Picture Description 
Here Insert Picture Description

5, install cmake

The latter is required to install cmake, first install, execute:

      apt install cmake

Here Raspberry Pi configuration is complete, the next step is to start to stick toolkit is installed

6, download OpenVINO toolkit for Raspbian installation package:

      https://download.01.org/openvinotoolkit/2018_R5/packages/l_openvino_toolkit_ie_p_2018.5.445.tgz

本次使用的版本是2018.5.445,安装请在下面链接中查看最新的安装包版本: 
https://software.intel.com/en-us/articles/OpenVINO-Install-RaspberryPI 
Here Insert Picture Description 
下载完后包位于Downloads/目录下,打开命令行

      cd ~/Downloads/

解压包:

      tar -xf l_openvino_toolkit_ie_p_2018.5.445.tgz

7、 配置路径与环境

执行以下命令,会自动对setupvars.sh文件做修改

      sed -i "s|<INSTALLDIR>|$(pwd)/inference_engine_vpu_arm|" inference_engine_vpu_arm/bin/setupvars.sh

再配置环境,有两种做法 
一种是临时的,只对该次的窗口有效

      source inference_engine_vpu_arm/bin/setupvars.sh

还有永久性的,执行:

      leafpad /home/pi/.bashrc

打开.bashrc文件,再最后一行添加一句:

      source /home/pi/Downloads/inference_engine_vpu_arm/bin/setupvars.sh

Here Insert Picture Description 
保存,再打开一个新的终端,如果出现:

      [setupvars.sh] OpenVINO environment initialized

就表示成功了 
Here Insert Picture Description

8、 添加USB规则

将当前Linux用户添加到users组:

      sudo usermod -a -G users "$(whoami)"

注:这里要说的是我们现在是root用户,如果打开新窗口的话起始用户是pi,所以出现[ setupvars.sh] OpenVINO environment initialized,是对于pi用户来说的,如果在新窗口中用root执行程序,其实并没有成功加载[ setupvars.sh] OpenVINO environment initialized,需要自己再执行一遍 
source /home/pi/Downloads/inference_engine_vpu_arm/bin/setupvars.sh,才能给root用户配置好OpenVINO environment initialized。这一点要特别注意,很细节的东西,我在这里折腾了好久。 
接下来配置USB规则,执行:

      sh inference_engine_vpu_arm/install_dependencies/install_NCS_udev_rules.sh

Here Insert Picture Description 
到这里就成功安装好计算棒所需的所有东西了

9、 demo测试验证安装是否成功

Construction and operation of an object detection example, this example performs face detection. 
Go to the sample source code file folder contains:

      cd inference_engine_vpu_arm/deployment_tools/inference_engine/samples
mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-march=armv7-a"
make -j2 object_detection_sample_ssd

Here Insert Picture Description 
After compilation and downloading network weights file:

      wget --no-check-certificate https://download.01.org/openvinotoolkit/2018_R4/open_model_zoo/face-detection-adas-0001/FP16/face-detection-adas-0001.bin
      wget --no-check-certificate https://download.01.org/openvinotoolkit/2018_R4/open_model_zoo/face-detection-adas-0001/FP16/face-detection-adas-0001.xml

Here Insert Picture Description 
Then the Internet to find their own picture of a human face execution

      ./armv7l/Release/object_detection_sample_ssd -m face-detection-adas-0001.xml -d MYRIAD -i <path_to_image>
#<path_to_image>是人脸图片的绝对路径

If it is successful, it will output a out_0.bmp picture in the build folder: 
Here Insert Picture Description 
here shows the calculation rods running success!

10, Opencv + python api call the method:

Sometimes we do in python development, there is also provided a Opencv + running example of python 
create a new folder, first create a face_detection.py file, writes:

      import cv2 as cv
# Load the model 
net = cv.dnn.readNet('face-detection-adas-0001.xml', 'face-detection-adas-0001.bin') 
# Specify target device 
net.setPreferableTarget(cv.dnn.DNN_TARGET_MYRIAD)
# Read an image 
frame = cv.imread('/path/to/image')
# Prepare input blob and perform an inference 
blob = cv.dnn.blobFromImage(frame, size=(672, 384), ddepth=cv.CV_8U) net.setInput(blob) 
out = net.forward()
# Draw detected faces on the frame 
for detection in out.reshape(-1, 7): 
    confidence = float(detection[2]) 
    xmin = int(detection[3] * frame.shape[1]) 
    ymin = int(detection[4] * frame.shape[0]) 
    xmax = int(detection[5] * frame.shape[1]) 
    ymax = int(detection[6] * frame.shape[0])
    if confidence > 0.5:
        cv.rectangle(frame, (xmin, ymin), (xmax, ymax), color=(0, 255, 0))
# Save the frame to an image file 
cv.imwrite('out.png', frame)

We just put in a download folder two files: face-detection-adas-0001.bin and face-detection-adas-0001.xml 
still picture face.jpeg for face detection of 
this time it is in with root privileges, we execute:

      source /home/pi/Downloads/inference_engine_vpu_arm/bin/setupvars.sh

Then execute:

      python3 face_detection.py

Run successfully without error, then run successfully, then we will see the result in the output folder, testing success 
Here Insert Picture Description

Guess you like

Origin www.cnblogs.com/cloudrivers/p/11459403.html