raspberry pi 4 树莓派4 代 64 位系统 aarch64,通过 yocto 编译安装 intel openvino 推理引擎

openvino 同时被 3 个专栏收录
2 篇文章 0 订阅
2 篇文章 0 订阅
1 篇文章 0 订阅

raspberry pi 4 树莓派4 代 64 位系统 aarch64,通过 yocto 编译安装 intel openvino 推理引擎

使用 intel neural compute stick 需要用到 openvino 推理引擎,然而 raspberry pi 4 aarch64 系统并没有编译好的安装包,需要借助 yocto 环境来构建安装包。本文基于 yocto zeus 分支演示环境准备及构建安装过程。

准备环境

操作系统: ubuntu 18.04
获取源代码:

git clone -b zeus https://git.yoctoproject.org/git/poky
git clone -b zeus https://git.yoctoproject.org/git/meta-intel
git clone -b zeus https://git.openembedded.org/meta-openembedded
git clone -b zeus https://github.com/kraj/meta-clang.git

准备烹饪的饼层

source poky/oe-init-build-env
bitbake-layers add-layer ../meta-intel
bitbake-layers add-layer ../meta-openembedded/meta-oe
bitbake-layers add-layer ../meta-openembedded/meta-python
bitbake-layers add-layer ../meta-clang

修改烹饪菜谱, conf/local.conf

# Default to setting automatically based on cpu count
BB_NUMBER_THREADS ?= "${@oe.utils.cpu_count()}"

# Default to setting automatically based on cpu count
PARALLEL_MAKE ?= "-j ${@oe.utils.cpu_count()}"

MACHINE = "raspberrypi4-64"
DISTRO = "poky"
USER_CLASSES ?= "buildstats image-mklibs image-prelink"
PATCHRESOLVE = "noop"
CONF_VERSION = "1"
...

开始烘烤

$ bitbake dldt-inference-engine
Loading cache: 100% |######################################################################################################################| Time: 0:00:00
Loaded 6297 entries from dependency cache.
Parsing recipes: 100% |####################################################################################################################| Time: 0:00:02
Parsing of 4786 .bb files complete (4770 cached, 16 parsed). 6299 targets, 219 skipped, 0 masked, 0 errors.
NOTE: Resolving any missing task queue dependencies

Build Configuration:
BB_VERSION           = "1.44.0"
BUILD_SYS            = "x86_64-linux"
NATIVELSBSTRING      = "universal"
TARGET_SYS           = "aarch64-poky-linux"
MACHINE              = "raspberrypi4-64"
DISTRO               = "poky"
DISTRO_VERSION       = "3.0.2"
TUNE_FEATURES        = "aarch64 cortexa72 crc crypto"
TARGET_FPU           = ""
DISTRO_NAME          = "Poky (Yocto Project Reference Distro)"
ROS_DISTRO           = "melodic"
ROS_VERSION          = "1"
ROS_PYTHON_VERSION   = "2"
meta                 
meta-poky            
meta-yocto-bsp       = "zeus:74f229160c7f4037107c1dad8f0d02128c080a7e"
meta-oe              
meta-python          
meta-multimedia      
meta-networking      
meta-perl            = "zeus:9e60d30669a2ad0598e9abf0cd15ee06b523986b"
meta-raspberrypi     = "heads/origin/zeus:9e67048f3247762419decddec16d21482b7ba8e6"
meta-security        = "zeus:ecd8c30af6b1b957b4fa814d3f25c40f060b3ac1"
meta-qt5             = "zeus:a582fd4c810529e9af0c81700407b1955d1391d2"
meta-python2         = "zeus:4400f9155ec193d028208cf0c66aeed2ba2b00ab"
meta-java            = "zeus:e022ca616e161fdfce44f2956e3587894282a0ab"
meta-tensorflow      = "master:fcbe23b2a33ec9d8c900fb6be30bd9344742c2ab"
meta-tensorflow-lite = "master:682d157f434348026fcd47e76b953988d80a8295"
meta-intel           = "zeus:32caa1705441615a07df01fe33ed12aee30e03d9"
meta-ros1-melodic    
meta-ros1            
meta-ros-common      = "zeus-draft:840ee20985c501555d46308ac0c16b67ee4ae253"
meta-rasp4           = "master:685ee71966ba84e00539f5be7a02692db887855a"
meta-clang           = "HEAD:711e593d5984aad3bf35c51b7ac4482982bc16c7"
workspace            = "<unknown>:<unknown>"

Initialising tasks: 100% |#################################################################################################################| Time: 0:00:01
Sstate summary: Wanted 60 Found 3 Missed 57 Current 409 (5% match, 87% complete)
NOTE: Executing Tasks
NOTE: Setscene tasks completed
Currently  1 running tasks (1873 of 1882)  99% |######################################################################################################## |
0: dldt-inference-engine-2019r3-r0 do_compile (pid 48314)  40% |####################################                                                     |

耐心等待烘烤结束

NOTE: Tasks Summary: Attempted 1882 tasks of which 1710 didn't need to be rerun and all succeeded.

更新食谱菜单

bitbake package-index
Loading cache: 100% |######################################################################################################################| Time: 0:00:01
Loaded 6297 entries from dependency cache.
Parsing recipes: 100% |####################################################################################################################| Time: 0:00:02
Parsing of 4786 .bb files complete (4784 cached, 2 parsed). 6299 targets, 219 skipped, 0 masked, 0 errors.
NOTE: Resolving any missing task queue dependencies

Build Configuration:
BB_VERSION           = "1.44.0"
BUILD_SYS            = "x86_64-linux"
NATIVELSBSTRING      = "universal"
TARGET_SYS           = "aarch64-poky-linux"
MACHINE              = "raspberrypi4-64"
DISTRO               = "poky"
DISTRO_VERSION       = "3.0.2"
TUNE_FEATURES        = "aarch64 cortexa72 crc crypto"
TARGET_FPU           = ""
DISTRO_NAME          = "Poky (Yocto Project Reference Distro)"
ROS_DISTRO           = "melodic"
ROS_VERSION          = "1"
ROS_PYTHON_VERSION   = "2"
meta                 
meta-poky            
meta-yocto-bsp       = "zeus:74f229160c7f4037107c1dad8f0d02128c080a7e"
meta-oe              
meta-python          
meta-multimedia      
meta-networking      
meta-perl            = "zeus:9e60d30669a2ad0598e9abf0cd15ee06b523986b"
meta-raspberrypi     = "heads/origin/zeus:9e67048f3247762419decddec16d21482b7ba8e6"
meta-security        = "zeus:ecd8c30af6b1b957b4fa814d3f25c40f060b3ac1"
meta-qt5             = "zeus:a582fd4c810529e9af0c81700407b1955d1391d2"
meta-python2         = "zeus:4400f9155ec193d028208cf0c66aeed2ba2b00ab"
meta-java            = "zeus:e022ca616e161fdfce44f2956e3587894282a0ab"
meta-tensorflow      = "master:fcbe23b2a33ec9d8c900fb6be30bd9344742c2ab"
meta-tensorflow-lite = "master:682d157f434348026fcd47e76b953988d80a8295"
meta-intel           = "zeus:32caa1705441615a07df01fe33ed12aee30e03d9"
meta-ros1-melodic    
meta-ros1            
meta-ros-common      = "zeus-draft:840ee20985c501555d46308ac0c16b67ee4ae253"
meta-rasp4           = "master:685ee71966ba84e00539f5be7a02692db887855a"
meta-clang           = "HEAD:711e593d5984aad3bf35c51b7ac4482982bc16c7"
workspace            = "<unknown>:<unknown>"

Initialising tasks: 100% |#################################################################################################################| Time: 0:00:00
Sstate summary: Wanted 0 Found 0 Missed 0 Current 24 (0% match, 100% complete)
NOTE: Executing Tasks
NOTE: Setscene tasks completed
Currently  1 running tasks (185 of 187)  98% |#########################################################################################################  |
0: package-index-1.0-r0 do_package_index - 44s (pid 94131)

然后在树莓派端查看最新的食谱菜单

rpi4:~/test$ sudo apt-get update
Password: 
Ign:1 http://192.168.168.192:8000/all ./ InRelease
Ign:2 http://192.168.168.192:8000/aarch64 ./ InRelease
Ign:3 http://192.168.168.192:8000/raspberrypi4_64 ./ InRelease
Get:4 http://192.168.168.192:8000/all ./ Release [1,213 B]
Get:5 http://192.168.168.192:8000/aarch64 ./ Release [1,217 B]
Get:6 http://192.168.168.192:8000/raspberrypi4_64 ./ Release [1,225 B]
Ign:7 http://192.168.168.192:8000/all ./ Release.gpg
Ign:8 http://192.168.168.192:8000/aarch64 ./ Release.gpg
Ign:9 http://192.168.168.192:8000/raspberrypi4_64 ./ Release.gpg
Get:10 http://192.168.168.192:8000/aarch64 ./ Packages [2,564 kB]
Fetched 2,567 kB in 2s (1,280 kB/s)    
Reading package lists... Done

查找食谱

rpi4:~/test$ acs dldt-
dldt-inference-engine-dbg - OpenVINO(TM) Toolkit - Deep Learning Deployment Toolkit - Debugging files
dldt-inference-engine-ptest - OpenVINO(TM) Toolkit - Deep Learning Deployment Toolkit - Package test files
dldt-inference-engine - OpenVINO(TM) Toolkit - Deep Learning Deployment Toolkit
dldt-inference-engine-vpu-firmware - OpenVINO(TM) Toolkit - Deep Learning Deployment Toolkit
dldt-inference-engine-doc - OpenVINO(TM) Toolkit - Deep Learning Deployment Toolkit - Documentation files
dldt-inference-engine-src - OpenVINO(TM) Toolkit - Deep Learning Deployment Toolkit - Source files
dldt-inference-engine-samples - OpenVINO(TM) Toolkit - Deep Learning Deployment Toolkit
dldt-inference-engine-dev - OpenVINO(TM) Toolkit - Deep Learning Deployment Toolkit - Development files

引入食谱

sudo apt-get install dldt-inference-engine dldt-inference-engine-samples

查看可用推理设备

rpi4:~/test$ hello_query_device 
Available devices: 
	Device: CPU
	Metrics: 
		AVAILABLE_DEVICES : [  ]
		SUPPORTED_METRICS : [ AVAILABLE_DEVICES SUPPORTED_METRICS FULL_DEVICE_NAME OPTIMIZATION_CAPABILITIES SUPPORTED_CONFIG_KEYS RANGE_FOR_ASYNC_INFER_REQUESTS RANGE_FOR_STREAMS ]
		FULL_DEVICE_NAME : Non Intel Architecture
		OPTIMIZATION_CAPABILITIES : [ FP32 INT8 BIN ]
		SUPPORTED_CONFIG_KEYS : [ CPU_BIND_THREAD CPU_THREADS_NUM CPU_THROUGHPUT_STREAMS DUMP_EXEC_GRAPH_AS_DOT DYN_BATCH_ENABLED DYN_BATCH_LIMIT EXCLUSIVE_ASYNC_REQUESTS PERF_COUNT ]
		RANGE_FOR_ASYNC_INFER_REQUESTS : { 1, 1, 1 }
		RANGE_FOR_STREAMS : { 1, 4 }
	Default values for device configuration keys: 
		CPU_BIND_THREAD : YES
		CPU_THREADS_NUM : 0
		CPU_THROUGHPUT_STREAMS : 1
		DUMP_EXEC_GRAPH_AS_DOT : ""
		DYN_BATCH_ENABLED : NO
		DYN_BATCH_LIMIT : 0
		EXCLUSIVE_ASYNC_REQUESTS : NO
		PERF_COUNT : NO

	Device: MYRIAD
	Metrics: 
		AVAILABLE_DEVICES : [ 1.2-ma2480 ]
		FULL_DEVICE_NAME : Intel Movidius Myriad X VPU
		SUPPORTED_METRICS : [ AVAILABLE_DEVICES FULL_DEVICE_NAME SUPPORTED_METRICS SUPPORTED_CONFIG_KEYS OPTIMIZATION_CAPABILITIES RANGE_FOR_ASYNC_INFER_REQUESTS ]
		SUPPORTED_CONFIG_KEYS : [ VPU_HW_STAGES_OPTIMIZATION VPU_LOG_LEVEL VPU_PRINT_RECEIVE_TENSOR_TIME VPU_NETWORK_CONFIG VPU_COMPUTE_LAYOUT VPU_CUSTOM_LAYERS VPU_IGNORE_IR_STATISTIC VPU_MYRIAD_FORCE_RESET VPU_MYRIAD_PLATFORM EXCLUSIVE_ASYNC_REQUESTS LOG_LEVEL PERF_COUNT CONFIG_FILE DEVICE_ID ]
		OPTIMIZATION_CAPABILITIES : [ FP16 ]
		RANGE_FOR_ASYNC_INFER_REQUESTS : { 3, 6, 1 }
	Default values for device configuration keys: 
		VPU_HW_STAGES_OPTIMIZATION : UNSUPPORTED TYPE
		VPU_LOG_LEVEL : UNSUPPORTED TYPE
		VPU_PRINT_RECEIVE_TENSOR_TIME : UNSUPPORTED TYPE
		VPU_NETWORK_CONFIG : UNSUPPORTED TYPE
		VPU_COMPUTE_LAYOUT : UNSUPPORTED TYPE
		VPU_CUSTOM_LAYERS : UNSUPPORTED TYPE
		VPU_IGNORE_IR_STATISTIC : UNSUPPORTED TYPE
		VPU_MYRIAD_FORCE_RESET : UNSUPPORTED TYPE
		VPU_MYRIAD_PLATFORM : UNSUPPORTED TYPE
		EXCLUSIVE_ASYNC_REQUESTS : UNSUPPORTED TYPE
		LOG_LEVEL : UNSUPPORTED TYPE
		PERF_COUNT : UNSUPPORTED TYPE
		CONFIG_FILE : UNSUPPORTED TYPE
		DEVICE_ID : UNSUPPORTED TYPE


我们来写一个简单的opencv dnn 推理测试,直接使用 caffe 模型,利用神经棒加速
test-opencv-dnn-vpu.py

#copyright dxxd, 
#东写西Do @CSDN
import numpy as np
import time
import cv2

caffe_root = '/home/pi/ml/'
image = cv2.imread('/home/pi/test/beagle.jpeg')
labels_file = caffe_root + 'models/ilsvrc12/classification/synset_words.txt'
prototxt = caffe_root + 'models/bvlc_googlenet/bvlc_googlenet.prototxt'
model = caffe_root + 'models/bvlc_googlenet/bvlc_googlenet.caffemodel'

# load the labels file
rows = open(labels_file).read().strip().split("\n")
classes = [r[r.find(" ") + 1:].split(",")[0] for r in rows]

blob = cv2.dnn.blobFromImage(image,1,(224,224),(104,117,123))
print("[INFO] loading model...")
net = cv2.dnn.readNetFromCaffe(prototxt,model)
net.setPreferableBackend(cv2.dnn.DNN_BACKEND_INFERENCE_ENGINE)
print("use dnn target myriad...")
net.setPreferableTarget(cv2.dnn.DNN_TARGET_MYRIAD)
# set the blob as input to the network and perform a forward-pass to
# obtain our output classification
net.setInput(blob)
start = time.time()
preds = net.forward()
end = time.time()
print("[INFO] classification took " + str((end-start)*1000) + " ms")

执行测试

rpi4:~/test$ python3 test-opencv-dnn-vpu.py
[INFO] loading model...
use dnn target myriad...
[INFO] classification took 3804.2752742767334 ms

欢迎评论交流,收藏备用,点赞转发分享!谢谢!

  • 0
    点赞
  • 0
    评论
  • 3
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

©️2021 CSDN 皮肤主题: 1024 设计师:白松林 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值