接着博主前面的系列博客继续讲,这篇来介绍上Intel的第二代加速神经棒的使用,主要还是参考官网来配置。前面很多博客也都访问过多家公司的官网,比较下来,Intel的真的很强大,满满的技术感。

Intel® Neural Compute Stick 2Learn AI programming at the edge with the newest generation of this tiny, fanless deep learning device.https://www.intel.com/content/www/us/en/developer/tools/neural-compute-stick/overview.html这里博主使用的是第二代,我们可以从第一代产品的官网上看到停止通知

第一代的Movidius™ Neural Compute SDK (NCSDK)不再更新了,都转用OpenVINO包来做了,且这个包同时支持第一代和第二代。

如何在树莓派上使用Intel NCS2来加速,可以参考博主之前博客

树莓派4B使用Intel Movidius NCS 2来进行推断加速_竹叶青lvye的博客-CSDN博客

一. PC(Ubuntu 20.04)硬件环境下使用Intel NCS2

博主此时的软件环境和写此篇博客时保持一致,然后自己又在淘宝上买了一个神经棒,就可以开始实验起来了。

 1.安装OpenVINO Runtime Toolkit

可以参考我前面的博客第四部分(c++环境下使用OpenVINO)来安装

OpenVINO使用介绍_竹叶青lvye的博客-CSDN博客_openvino使用https://blog.csdn.net/jiugeshao/article/details/124288250?spm=1001.2014.3001.5502

注意环境变量配置结束后,这边还需要多一步,就是安装下神经棒的驱动,cd到如下目录下(结合自己的路径)

执行命令

./install_NCS_udev_rules.sh

2. 列举当前支持的推断设备

参考官网,可以通过如下API来获取当前电脑上所能提供的推断设备

import openvino.runtime as ovcore = ov.Core()
for device in core.available_devices:print(device)

结果如下:

/home/sxhlvye/anaconda3/envs/testOpenVINO2/bin/python3.6 /home/sxhlvye/trial4/test_available.py
[E:] [BSL] found 0 ioexpander device
CPU
GNA
GPU
MYRIADProcess finished with exit code 0

博主这边把NSC 2神经棒拔掉再运行上面代码,输出结果如下:

/home/sxhlvye/anaconda3/envs/testOpenVINO2/bin/python3.6 /home/sxhlvye/trial4/test_available.py
[E:] [BSL] found 0 ioexpander device
CPU
GNA
GPUProcess finished with exit code 0

可看到MYRIAD设备不存在了,符合期望结果。

 3.在神经棒上进行推断

参考前面博客OpenVINO使用介绍_竹叶青lvye的博客-CSDN博客_openvino使用

还是用上面博客里生成的openVINO runtime中间模型Intermediate Representation (IR)来推断小猫图片,代码如下:

import cv2
import numpy
import openvino.runtime as ov
import numpy as np
import time
from tensorflow.keras.applications.resnet50 import preprocess_input, decode_predictionsimport openvino.runtime as ovcore = ov.Core()
for device in core.available_devices:print(device)cpu_device_name = core.get_property("CPU", "FULL_DEVICE_NAME")
print(cpu_device_name)cpu_device_name = core.get_property("GNA", "FULL_DEVICE_NAME")
print(cpu_device_name)cpu_device_name = core.get_property("GPU", "FULL_DEVICE_NAME")
print(cpu_device_name)cpu_device_name = core.get_property("MYRIAD", "FULL_DEVICE_NAME")
print(cpu_device_name)core = ov.Core()
model = core.read_model("./resnet/saved_model.xml")
#model.reshape([1,224,224,3])compiled_model = core.compile_model(model, "MYRIAD")
infer_request = compiled_model.create_infer_request()img = cv2.imread('2008_002682.jpg')
img = cv2.resize(img, (224, 224))
img_np = np.array(img, dtype=np.float32) / 255.img_np = np.expand_dims(img_np, axis=0)
print(img_np.shape)# Create tensor from external memory
input_tensor = ov.Tensor(array=img_np, shared_memory=False)infer_request.set_input_tensor(input_tensor)t_model = time.perf_counter()
infer_request.start_async()
infer_request.wait()
print(f'do inference cost:{time.perf_counter() - t_model:.8f}s')# Get output tensor for model with one output
output = infer_request.get_output_tensor()
output_buffer = output.data# output_buffer[] - accessing output tensor data
print(output_buffer.shape)
print('Predicted:', decode_predictions(output_buffer, top=5)[0])print("ok")

执行出现如下错误:

Traceback (most recent call last):
  File "/home/sxhlvye/trial4/test_inference2.py", line 30, in <module>
    compiled_model = core.compile_model(model, "MYRIAD")
  File "/home/sxhlvye/intel/openvino_2022/python/python3.6/openvino/runtime/ie_api.py", line 266, in compile_model
    super().compile_model(model, device_name, {} if config is None else config)
RuntimeError: Cannot get length of dynamic dimension

报错原因是模型输入shape不是静态的,所以得让shape固定,官网也有相关方面说明

Changing input shapes — OpenVINO™ documentation

这边只需将上面博主所写代码解注释即可(将#model.reshape([1,224,224,3])改为model.reshape([1,224,224,3]),修改后再次运行代码,结果如下:

/home/sxhlvye/anaconda3/envs/testOpenVINO2/bin/python3.6 /home/sxhlvye/trial4/test_inference2.py
2022-05-08 08:38:26.794065: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudart.so.11.0
[E:] [BSL] found 0 ioexpander device
CPU
GNA
GPU
MYRIAD
Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
GNA_SW
Intel(R) UHD Graphics 630 [0x3e9b] (iGPU)
Intel Movidius Myriad X VPU
(1, 224, 224, 3)
do inference cost:0.05454781s
(1, 1000)
Predicted: [('n01930112', 'nematode', 0.12646484), ('n03041632', 'cleaver', 0.03668213), ('n03838899', 'oboe', 0.029830933), ('n02783161', 'ballpoint', 0.025115967), ('n03804744', 'nail', 0.024139404)]
okProcess finished with exit code 0

上面是跑在intel NCS 2上,博主这边也分别在CPU和GPU上进行了测试

上面代码对应处修改为 compiled_model = core.compile_model(model, "CPU"),运行下程序,结果如下(部分信息)

(1, 224, 224, 3)
do inference cost:0.02203732s
(1, 1000)
Predicted: [('n01930112', 'nematode', 0.13559894), ('n03041632', 'cleaver', 0.041396398), ('n03838899', 'oboe', 0.034457874), ('n02783161', 'ballpoint', 0.02541826), ('n04270147', 'spatula', 0.023189805)]
okProcess finished with exit code 0

上面代码对应处修改为 compiled_model = core.compile_model(model, "GPU"),运行下程序,结果如下(部分信息)

do inference cost:0.03005712s
(1, 1000)
Predicted: [('n01930112', 'nematode', 0.13559903), ('n03041632', 'cleaver', 0.041396033), ('n03838899', 'oboe', 0.03445781), ('n02783161', 'ballpoint', 0.025418187), ('n04270147', 'spatula', 0.023189766)]
ok

大家会奇怪,都跑在GPU上了,怎么速度还不如CPU呢,是因为OpenVINO不支持英伟达的显卡,所以并没有跑在博主GTX 1660Ti显卡上,而是跑在Intel(R) UHD Graphics 630 [0x3e9b] (iGPU)上面。官网这边也提到了

Configurations for Intel® Processor Graphics (GPU) with Intel® Distribution of OpenVINO™ toolkit — OpenVINO™ documentation

二.官网资料梳理

OpenVINO的官网资料零散部分着,跳跃链接实在太多,这里博主为了方便以后快速能找到对应知识点,简单进行了梳理。

正常我们要去看关于神经加速棒的介绍,会首先到此网站上来

Intel® Movidius™ Neural Compute Stick

上面一些重要信息是说了,第一个代已经停止更新SDK了,后面第二代神经棒就是统一用OpenVINO了,此包也支持第一代神经棒。同时此页面也提供了访问神经计算棒第二代介绍的入口。

NCS 2的介绍主页面

Get Started with Intel® Neural Compute Stick 2

重要信息如下

1.人家说了是拿2019版的toolkit来示例介绍的,用最新的小伙伴们会发现,step-by-step按照官网整时,发现并没有改页面提到的demo示例程序,所以不用太纠结

2. 官网也是有很多NCS 2在树莓派系列上的使用介绍的

3. OpenVINO方面的使用示例可以参考ncappzoo

4. https://github.com/openvinotoolkit/open_model_zoo 里面也有很多丰富的资料

5.关于OpenVNO的安装、使用介绍可以从此页面上的入口处切换

6.Get Started上是安装方面的介绍

OpenVINO Runtime的安装方面,其中Using Installer是通过下载安装包方式来安装,也提到了如何去配置不同硬件的操作(GPU、NCS 2等),配置环境变量;From PYPI是通过pip方式来安装,针对python环境;From APT是通过apt install方式来安装,对应Using Installer方式;From YUM是针对Red Hat Enterprise Linux 8, 64-bit系统;From Anaconda是用conda方式安装,针对python环境;using Docker是通过Docker方式安装。

博主常用的是Using Installer和From PYPI方式。

7.其它的关于OpemVINO Development的安装、开发demo都可以从上面页面找到入口。

8.模型如何转为OpenVINO模型,以及结合自己的使用见Documentation

9.对于博主来讲,应该主要是拿OpenVINO用来在推断阶段加速,虽然你官网提供了训练的简单示例

OpenVINO™ Training Extensions — OpenVINO™ documentation

training_extensions/train.ipynb at master · openvinotoolkit/training_extensions · GitHub

但太小众了,后面主要还是用tensorflow、pytorch框架来进行训练,通过转换模型方式来使用。

剩余的就不梳理了,看多了就好了。

Intel Movidius Neural Computer Stick 2使用(PC-Based Ubuntu)相关推荐

  1. Intel Neural Compute Stick 2代部署步骤

    环境介绍: 我是win 7 64位系统,用VMware虚拟机装了个Ubuntu 16.04LTS 64位的linux系统: 接下来是参照Intel给的参考步骤开始部署2代NCS的工作环境. 官方资料: ...

  2. Intel Movidius - Install the Intel Distribution of OpenVINO Toolkit for Raspbian* OS (树莓派系统) 环境构建

    Intel Movidius - Install the Intel Distribution of OpenVINO Toolkit for Raspbian* OS (树莓派系统) 环境构建 ht ...

  3. 因特尔计算棒(Intel Movidius Necural Compute)

    Intel Movidius Necural Compute(NCS)为因特尔开发的 轻巧,无风扇,深度学习设备,主要用于边缘计算,通过usb 3.0接口与主机或者开发板相链接, 支持window和u ...

  4. 从零开始搭建树莓派 + intel movidius 神经元计算棒2代深度学习环境

    从零开始搭建树莓派+intel movidius 神经元计算棒2代深度学习环境 摘要 材料硬件: 步骤: 1. 下载树莓派镜像并解压 2. 烧写镜像 3. 启动树莓派 4. 配置树莓派 5. 安装cm ...

  5. 树莓派4B与Intel Movidius计算棒2代实现深度学习应用加速

    树莓派4B与Intel Movidius计算棒2代实现人脸识别加速实例 树莓派 树莓派介绍 教程 操作 换源部分: 安装cmake Intel 神经计算棒环境配置 Intel 神经计算棒简介 Open ...

  6. 树莓派3b+和 intel movidius 神经元计算棒2代 跑yolo v3 tiny

    本帖子主要是参考了以下两篇: 第一篇: 从零开始搭建树莓派 + intel movidius 神经元计算棒2代深度学习环境 这篇文章主要目录如下: 摘要 材料硬件: 步骤: 1.    下载树莓派镜像 ...

  7. 可微神经计算机(Differentiable neural computer)的介绍

    可微神经计算机的介绍 一.介绍 二.控制器 三.控制信息向量 四.存储器读写机制 写操作 读操作 4.1 Content-based addressing 4.2 Dynamic memory all ...

  8. 如何在 Linux 上使用 Neural Compute Stick 2 运行 OpenVINO

    首先,将神经计算棒 2 (NCS2) 插入 USB 端口.然后,在终端中,运行: Lsusb 您应该看到类似下面的内容: 总线 003 设备 009: ID 03e7:2485 英特尔 Movidiu ...

  9. 搭建树莓派 4B + intel movidius 神经元计算棒2代深度学习环境

    换源 这样下载速度会快一点稳定一点: 使用管理员权限,执行 sudo leafpad /etc/apt/sources.list 在打开的文件中,用#注释掉原文件内容,用以下内容取代: deb htt ...

最新文章

  1. CDN(内容分发网络)技术原理(转)
  2. 跟我一起学Redis之五种基本类型及其应用场景举例(干了6个小时)
  3. 使用visio 提示此UML形状所在的绘图页不是UML模型图的一部分 请问这个问题怎么解决?...
  4. Hibernate框架 简述
  5. 程序员说的demo是什么意思_“黄龄说的什么意思”???
  6. 动态加载网上或者本地场景的后续
  7. 在IDEA中创建Maven项目和添加tomcat
  8. php无框架开发web项目,web.framework
  9. ArcMap中无法添加ArcGIS Online底图的诊断方法
  10. 学习AccessibilityService实现微信抢红包插件
  11. 科技文献检索(二)——文献定义及类型
  12. 【22/04】Chrome 里的请求报错 “CAUTION: Provisional headers are shown“ 是什么意思?
  13. 微信查询对账单对账+数据读取解析入库
  14. sphinx-for-chinese在windows下安装与使用方法
  15. Java计算百分比方法
  16. jQueryXML笔记
  17. 9款免费的Windows远程协助软件
  18. 信息安全(网络安全顶会)
  19. 阿里云云栖社区强烈推荐的十本经典机器学习相关书籍
  20. Docker-第一课

热门文章

  1. 查看局域网计算机软件,局域网查看工具(LanSee)
  2. 计算机绘图与三维造型课后题,计算机绘图(中级):AutoCAD三维建模与深入运用上机实验指导...
  3. 前端智能化的未来 10 年,越早入行越吃香!
  4. so easy!从头教你用mkdocs构建个人博客系统~
  5. scms审计笔记之注入
  6. linux 解压rar格式的文件怎么打开,linux服务器怎么解压rar格式的文件
  7. react native在growth stack中的角色思考
  8. 华为Atlas200DK环境配置指南(版本20.0.0)
  9. H5实现可拖动的360度环拍物品展示(1)
  10. HTML5开发手机项目-个人总结