在树莓派3B+上部署Intel NCS2神经网络计算棒
RASPI 2019-01-14 10:06248(转发)
2018.12.20日 英特尔更新了OpenVINO Toolkit R5版本。该版本添加了对树莓派的支持。作为NCS2的官方开发套件,OpenVINO在此之前只能在台式机ubuntu 16.04上使用。而在树莓派上使用的ncsdk并不支持NCS2计算棒。通过在树莓派上部署OpenVino,可实现在树莓派上使用NCS2加速神经网络计算。
本博客依照官方资料编写,博主在确认可行(排雷)后,第一时间写下此博文。官方链接:
https://software.intel.com/en-us/articles/OpenVINO-Install-RaspberryPI#install-the-package
系统要求:
你需要一个安装了Raspbian 9 OS 32位,也就是官方系统的树莓派3B+。
注意事项:
一般来说, 所有的步骤都是不可或缺的,除非您在之前已经部署过了一些模块。
OpenVINO toolkit for Raspbian OS 只包含了MYRIAD插件。
总体步骤:
安装Intel®️ Distribution of OpenVINO™️ toolkit。
设置环境变量。
添加USB规则。
运行例程确认安装正确。
安装包所含内容:
1.推理引擎
2.OpenCV 4.0
3.样本代码
安装步骤:
下载Intel®️ Distribution of OpenVINO™️ toolkit。
(此处默认下载目录,安装目录为~/Downloads)
打开终端:
至此,NCS2环境部署已完成。我们使用官方例程进行验证。
12345678910111213141516 | 1.转到包含示例源码的文件夹:cd inference_engine_vpu_arm/deployment_tools/inference_engine/samples 2.新建文件夹build:mkdir build && cd build 3.构建对象检测示例:cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS=”-march=armv7-a”make -j4 object_detection_sample_ssd 4.下载预先训练的人脸检测模型:wget –no-check-certificate https://download.01.org/openvinotoolkit/2018_R4/open_model_zoo/face-detection-adas-0001/FP16/face-detection-adas-0001.binwget –no-check-certificate https://download.01.org/openvinotoolkit/2018_R4/open_model_zoo/face-detection-adas-0001/FP16/face-detection-adas-0001.xml 5.运行示例测试结果:(path_to_image 为带人脸的图片路径)./armv7l/Release/object_detection_sample_ssd -m face-detection-adas-0001.xml -d MYRIAD -i <path_to_image> |
使用OpenCV API运行人脸检测模型
新建一个名为openvino_fd_myriad.py的文件,内容如下:(’/path/to/image‘替换为图片绝对路径)
12345678910111213141516171819202122232425262728 | 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) |
然后运行脚本
1 | python3 openvino_fd_myriad.py |
以上完成后,便成功在树莓派上部署NCS2计算棒的运行环境了。文章标签: NCS计算棒