5g与edge ai

In my previous articles, I have discussed the basics of the OpenVINO toolkit, OpenVINO’s Model Optimizer and Inference Engine. In this article, we will be exploring:-

在之前的文章中,我讨论了OpenVINO工具箱 ,OpenVINO的模型优化器和推理引擎的基础 。 在本文中,我们将探索:

  • Types of Computer Vision models.计算机视觉模型的类型。
  • Pre-trained models in OpenVINO.OpenVINO中的预训练模型。
  • Downloading Pre-trained models.下载预训练的模型。
  • Deploying an Edge App using a pre-trained model.使用预先训练的模型部署Edge App。

计算机视觉模型的类型 (Types of Computer Vision Models)

There are different types of computer vision models which are used for various purposes. But the three main computer vision models are:-

有多种类型的计算机视觉模型可用于各种目的。 但是,三种主要的计算机视觉模型是:

  • Classification分类
  • Object Detection物体检测
  • Segmentation分割

The classification model identifies the “class” of a given image or an object in the image. The classification can be binary i.e. Yes or No, or thousands of classes like a person, apple, car, cat, etc.. There are several classification models like- ResNet, DenseNet, Inception, etc..

分类模型识别给定图像或图像中对象的“类别”。 分类可以是二进制的,即“是”或“否”,也可以是数千种类别,例如人,苹果,汽车,猫等。有几种分类模型,例如ResNet,DenseNet,Inception等。

Object Detection models are used to determine the objects present in the image and oftentimes draw bounding boxes around the detected objects. They also use classification to identify the class of the object inside the bounding box. You can also set a threshold for bounding boxes so that you can reject low-threshold detections. RCNN, Fast-RCNN, YOLO, etc. are some examples of Object Detection Models.

对象检测模型用于确定图像中存在的对象,并经常在检测到的对象周围绘制边界框。 他们还使用分类来识别边界框内对象的类。 您还可以为边界框设置阈值,以便拒绝低阈值检测。 RCNN,Fast-RCNN,YOLO等是对象检测模型的一些示例。

Segmentation models perform pixel-wise classification in the given image. There are two different types of Segmentation- Semantic Segmentation and Instance Segmentation. In Semantic Segmentation, all the objects which belong to the same class are considered the same, whereas in Instance Segmentation each and every object is considered different even if it belongs to the same class. For example, if there are five people in an image, a Semantic Segmentation model will treat all five of them as same, whereas in Instance Segmentation model all five of them will be treated differently. U-Net, DRN, etc..

分割模型在给定图像中执行逐像素分类。 有两种不同类型的细分-语义细分和实例细分。 在语义分割中,属于同一类的所有对象都被认为是相同的,而在实例分割中,即使每个对象属于同一类,也被认为是不同的。 例如,如果图像中有五个人,则语义分割模型将把所有五个人视为相同,而在实例分割模型中,将把所有五个人区别对待。 U-Net,DRN等。

OpenVINO中的预训练模型 (Pre-trained Models in OpenVINO)

Pre-trained models, as the name suggests, are models which are already trained with high, or even cutting edge accuracy. Training a deep learning model requires a lot of time and computation power. Although, it is exciting to create your own model and train it by fine-tuning the hyperparameters (number of hidden layers, learning rate, activation function, etc.) to achieve higher accuracy. But, this needs hours of work.

顾名思义,预训练模型是已经以高甚至尖端精度进行训练的模型。 训练深度学习模型需要大量时间和计算能力。 虽然,创建自己的模型并通过微调超参数(隐藏层数,学习率,激活函数等)以达到更高的精度来训练它是令人兴奋的。 但是,这需要数小时的工作。

By using pre-trained models, we avoid the need for large-scale data collection and long, costly training. Given knowledge of how to preprocess the inputs and handle the outputs of the network, you can plug these directly into your own app.

通过使用预先训练的模型,我们避免了大规模数据收集和长期,昂贵的训练的需要。 在掌握了如何预处理输入和处理网络输出的知识之后,您可以将其直接插入自己的应用程序中。

OpenVINO has a lot of pre-trained models in the model zoo. The model zoo has Free Model Set and Public Model Set, the Free Model Set contains pre-trained models already converted to Intermediate Representation(.xml and .bin) using the Model Optimizer. These models can be used directly with the Inference Engine. The Public Model Set contains pre-trained models, but these are not converted to the intermediate representation.

OpenVINO在模型动物园中有很多预先训练的模型 。 模型动物园具有“免费模型集”和“公共模型集”,“免费模型集”包含已使用“模型优化器”转换为中间表示(.xml和.bin)的预训练模型。 这些模型可以直接与推理引擎一起使用。 公共模型集包含预训练的模型,但是不会将其转换为中间表示。

下载预训练的模型 (Downloading Pre-trained Models)

In this article, I will be loading the “vehicle-attributes-recognition-barrier-0039” model from the open model zoo.

在本文中,我将从开放模型动物园加载“ vehicle-attributes-recognition-barrier-0039”模型。

To download a pre-trained model, follow these steps(type the commands in Command Prompt/Terminal):-

要下载预训练的模型,请按照以下步骤操作(在命令提示符/终端中键入命令):

  1. Navigate to the Model Downloader directory导航到“模型下载器”目录

For Linux:-

对于Linux:-

cd /opt/intel/openvino/deployment_tools/open_model_zoo/tools/model_downloader

For Windows:-

对于Windows:-

cd C:/Program Files (x86)/IntelSWTools/openvino

I have used the default installation directory in the above command if your installation directory is different then navigate to the appropriate directory.

如果您的安装目录不同,那么我在上面的命令中使用了默认的安装目录,然后导航到适当的目录。

2. Run the downloader.py

2.运行downloader.py

The downloader Python file requires some arguments, you can use the “-h” argument to see available arguments.

下载器的Python文件需要一些参数,您可以使用“ -h”参数查看可用参数。

python downloader.py -h

Let’s download the model,

让我们下载模型,

python downloader.py --name vehicle-attributes-recognition-barrier-0039 --precisions -FP32 --output_dir /home/pretrained_models
  • — name → model name.

    —名称 →型号名称。

  • — precision → model precision (FP16, FP32 or INT8).

    —精度 →模型精度(FP16,FP32或INT8)。

  • — output_dir → path where to save models.

    — output_dir →保存模型的路径。

After successfully downloading the model, navigate to the path where you have downloaded the model and you will find the “.xml” and “.bin” files of the model.

成功下载模型后,导航至下载模型的路径,您将找到模型的“ .xml”和“ .bin”文件。

Kindly refer the documentation to know more details(inputs and outputs) about the model.

请参考文档以了解有关该模型的更多详细信息(输入和输出)。

部署Edge应用 (Deploying an Edge App)

Now, since we have downloaded the pre-trained model, Let’s deploy it in an Edge app.

现在,由于我们已经下载了预训练的模型,因此让我们将其部署在Edge应用程序中。

Let’s create a file “inference.py” to define and work with the inference engine. In my previous article, about the inference engine, I have used different functions, but here I will be defining a class.

让我们创建一个文件“ inference.py”来定义和使用推理引擎。 在上一篇关于推理引擎的文章中 ,我使用了不同的函数,但是在这里我将定义一个类。

from openvino.inference_engine import IENetwork, IECoreclass Network:    def __init__(self):        self.plugin = None        self.network = None        self.input_blob = None        self.exec_network = None        self.infer_request = None    def load_model(self):        self.plugin = IECore()        self.network = IENetwork(model='path_to_xml', weights='path_to_bin')

        ### Defining CPU Extension path        CPU_EXT_PATH=      "/opt/intel/openvino/deployment_tools/inference_engine/lib/intel64/ libcpu_extension_sse4.so"           ### Adding CPU Extension        plugin.add_extension(CPU_EXT_PATH,"CPU")        ### Get the supported layers of the network        supported_layers = plugin.query_network(network=network, device_name="CPU")            ### Finding unsupported layers        unsupported_layers = [l for l in network.layers.keys() if l not in supported_layers]            ### Checking for unsupported layers        if len(unsupported_layers) != 0:            print("Unsupported layers found")            print(unsupported_layers)            exit(1)        ### Loading the network        self.exec_network =             self.plugin.load_network(self.network,"CPU")        self.input_blob  = next(iter(self.network.inputs))        print("MODEL LOADED SUCCESSFULLY!!!)    def get_input_shape(self):        return self.network.inputs[self.input_blob].shape    def synchronous_inference(self,image):          self.exec_network.infer({self.input_blob: image})    def extract_output(self):        return self.exec_network.requests[0].outputs

Don’t get confused! I’ll explain every function.

不要困惑! 我将解释每个功能。

  • __init__(self):

    __在自身):

It’s the constructor of the class Network, where I initialize the data members of the class.

它是网络类的构造函数,在这里我初始化类的数据成员。

  • load_model(self):

    load_model(self):

As the name suggests, it is used to load the model(pre-trained), in this function we:-

顾名思义,它用于加载模型(预先训练),在此函数中,我们:-

▹ Declared an IECore object.

ed声明为IECore对象。

▹ Declare an IENetwork object.

▹声明IENetwork对象。

▹ Loaded the model xml and bin files.

▹加载了模型xml和bin文件。

▹ Checked for unsupported layers

▹检查了不支持的图层

▹ Load the IENetwork object in IECore Object.

▹将IENetwork对象加载到IECore对象中。

  • get_input_shape(self):

    get_input_shape(self):

Returns the shape of the input required by the model

返回模型所需输入的形状

  • synchronous_inference(self, image):

    sync_inference(自己,图片):

Performs Synchronous Inference on the input image

在输入图像上执行同步推理

  • extract_output(self):

    extract_output():

Returns the output from the model after the inference is completed.

推断完成后,返回模型的输出。

So, that was “inference.py”, now let’s create a file “main.py”.

因此,那是“ inference.py”,现在让我们创建一个文件“ main.py”。

import cv2import numpy as npfrom inference import Networkdef preprocessing(image,height,width):    ### Resize the Image    image = cv2.resize(image,(width,height))    ### Add color channel first    image = image.transpose((2,0,1))    ### Add Batch Size    image  = np.reshape((image,(1,3,height,width))    return image
  1. While resizing the image using the resize() of OpenCV, you should give the width first and then the height.使用OpenCVresize()调整图像大小时,应首先提供宽度,然后再提供高度。
  2. According to the documentation, the model reads the channels first and then the image dimensions, but OpenCV reads the image dimensions first and then the channels, so I’ve used the transpose(), to bring the color channel first.

    根据文档 ,模型首先读取通道,然后读取图像尺寸,但是OpenCV首先读取图像尺寸,然后读取通道,因此我使用了transpose()首先打开了彩色通道。

  3. The model takes the input as (batch_size, color_channels, height, width), so we reshape the image to give a “batch_size” which is 1.该模型将输入作为(batch_size,color_channels,height,width),因此我们将图像重塑为“ batch_size”,即1。
def main():    ### Read the image    image = cv2.imread('path_to_image')    ### Declare a Network Object    plugin = Network()    ### Input shape required by model    input_shape = plugin.get_input_shape()    height = input_shape[2]    width = input_shape[3]    ### Preprocess the input        p_image = preprocessing(image,height,width)    ### Perform Synchronous Inference    plugin.synchronous_inference(p_image)    ### Extract the output    results = plugin.extract_output()

According to the documentation, the output(results) from the model is a dictionary, which contains the following information:-

根据文档,模型的输出(结果)是一个字典,其中包含以下信息:

  1. “color”, shape: [1, 7, 1, 1] — Softmax output across seven color classes [white, grey, yellow, red, green, blue, black]“颜色”,形状:[1、7、1、1]-跨七个颜色类别[白色,灰色,黄色,红色,绿色,蓝色,黑色]的Softmax输出
  2. “type”, shape: [1, 4, 1, 1] — Softmax output across four type classes [car, bus, truck, van]“类型”,形状:[1、4、1、1] –跨四个类型类别[汽车,公共汽车,卡车,货车]的Softmax输出

Since it is a softmax output, we need to map the index of the maximum value with the color and the type.

由于它是softmax输出,因此我们需要将最大值的索引与颜色和类型进行映射。

    color = ['white','grey','yellow','red','green','blue','black']    vehicle = ['car','bus','truck','van']    ### Finding out the color and type    result_color = str(color[np.argmax(results['color'])])    result_type = str(vehicle[np.argmax(results['type'])])### Add details to image    font = cv2.FONT_HERSHEY_SIMPLEX    font_scale = 1    col = (0, 255,0) #BGR    thickness = 2        color_text= 'color: '+result_color    type_text = 'vehicle: '+result_type    cv2.putText(image,color_text,(50,50), font, font_scale, col, thickness, cv2.LINE_AA)    cv2.putText(image,type_text,(50,75), font, font_scale, col, thickness, cv2.LINE_AA)    ### Save the image    cv2.imwrite('path/vehicle.png',image)if __name__=="__main__":    main()

I tried for two vehicles and I got the following output:-

我尝试了两辆车,结果如下:

Source: Author
资料来源:作者

Well, That’s all folks. I hope by now you have a proper understanding of how to deploy an AI edge application using OpenVINO. OpenVINO has various pre-trained models for several applications. Try implementing different pre-trained models available in the OpenVINO model zoo and create your own edge application. Thank you so much for reading my article.

好吧,这就是所有人。 我希望到目前为止,您对如何使用OpenVINO部署AI边缘应用程序有正确的了解。 OpenVINO具有针对各种应用的各种预训练模型。 尝试实施OpenVINO 模型库中可用的不同的预训练模型,然后创建自己的边缘应用程序。 非常感谢您阅读我的文章。

翻译自: https://towardsdatascience.com/deploying-an-ai-edge-app-using-openvino-aa84e87c4577

5g与edge ai


http://www.taodudu.cc/news/show-863640.html

相关文章:

  • 法庭上认可零和博弈的理论吗_从零开始的本征理论
  • 极限学习机和支持向量机_极限学习机I
  • 如何在不亏本的情况下构建道德数据科学系统?
  • ann人工神经网络_深度学习-人工神经网络(ANN)
  • 唐宇迪机器学习课程数据集_最受欢迎的数据科学和机器学习课程-2020年8月
  • r中如何求变量的对数转换_对数转换以求阳性。
  • 美团脱颖而出的经验_使数据科学项目脱颖而出的6种方法
  • aws rds同步_将数据从Python同步到AWS RDS
  • 扫描二维码读取文档_使用深度学习读取和分类扫描的文档
  • 电路分析导论_生存分析导论
  • 强化学习-第3部分
  • 范数在机器学习中的作用_设计在机器学习中的作用
  • 贝叶斯深度神经网络_深度学习为何胜过贝叶斯神经网络
  • 模型监控psi_PSI和CSI:前2个模型监控指标
  • flask渲染图像_用于图像推荐的Flask应用
  • pytorch贝叶斯网络_贝叶斯神经网络:2个在TensorFlow和Pytorch中完全连接
  • 稀疏组套索_Python中的稀疏组套索
  • deepin中zz_如何解决R中的FizzBu​​zz问题
  • 图像生成对抗生成网络gan_GAN生成汽车图像
  • 生成模型和判别模型_生成模型和判别模型简介
  • 机器学习算法 拟合曲线_制定学习曲线以检测机器学习算法中的错误
  • 重拾强化学习的核心概念_强化学习的核心概念
  • gpt 语言模型_您可以使用语言模型构建的事物的列表-不仅仅是GPT-3
  • 廉价raid_如何查找80行代码中的廉价航班
  • 深度学习数据集制作工作_创建我的第一个深度学习+数据科学工作站
  • pytorch线性回归_PyTorch中的线性回归
  • spotify音乐下载_使用Python和R对音乐进行聚类以在Spotify上创建播放列表。
  • 强化学习之基础入门_强化学习基础
  • 在置信区间下置信值的计算_使用自举计算置信区间
  • 步进电机无细分和20细分_细分网站导航会话

5g与edge ai_使用OpenVINO部署AI Edge应用相关推荐

  1. IEEE EDGE 2020论文:Astraea — 以优雅的方式在边缘部署AI服务

    简介: 近日,阿里云边缘计算团队博士后付哲的论文<Astraea: Deploy AI Services at the Edge in Elegant Ways>入选2020年IEEE边缘 ...

  2. 使用OpenVINO部署ONNX模型

    做深度学习神经网络的设计.训练与部署,往往会困扰于不同的操作系统,不同的深度学习框架,不同的部署硬件,以及不同的版本.由于相互之间的不兼容,给开发使用者造成了很大的不便. 联合使用OpenVINO和O ...

  3. 使用FastDeploy在英特尔CPU和独立显卡上端到端高效部署AI模型

    目录 1.1 产业实践中部署AI模型的痛点 1.1.1  部署模型的典型流程 1.1.2 端到端的AI性能 1.1.3 部署模型的难点和痛点 1.2 FastDeploy简介 1.3 英特尔独立显卡简 ...

  4. OpenVINO部署Mask-RCNN实例分割网络

    点击上方"3D视觉工坊",选择"星标" 干货第一时间送达 极市导读 OpenVINO是英特尔推出的一款全面的工具套件,用于快速部署应用和解决方案,支持计算机视觉 ...

  5. 边缘计算 ai_什么是边缘AI计算?

    边缘计算 ai Edge AI starts with edge computing. Also called edge processing, edge computing is a network ...

  6. YOLOv5实现自定义对象训练与OpenVINO部署全解析

    点击上方"小白学视觉",选择加"星标"或"置顶" 重磅干货,第一时间送达 本文转自:opencv学堂 大家好,前面写了一个OpenVINO部 ...

  7. OpenVINO 部署 YOLOv5 转换IR文件

    环境: Windows:10 YOLOv5:3.1 Python 3.7.10 torch:1.7.0+cu101 torchvision:0.8.1+cu101 OpenVINO:openvino_ ...

  8. ai算子是什么_肇观电子刷新端侧AI芯片性能记录并发布“5分钟部署”AI开发平台 - 企业资讯...

    基于多年研发的CVKit™ NN IP的N1系列SoC芯片刷新了端侧AI芯片性能记录.领先的每TOPs处理帧数,实时数据流处理能力,支持高精度FP16神经网络模型直接无损部署,高性能的INT8网络支持 ...

  9. 谷歌终于推出TensorFlow Lite,实现在移动设备端部署AI

    安妮 编译整理 量子位 出品 | 公众号 QbitAI 还得从半年前说起. 今年5月的谷歌I/O大会上,安卓工程副总裁Dave Burke宣布将推出一个专门为移动设备优化的TensorFlow,称为T ...

最新文章

  1. CUBLAS_STATUS_ALLOC_FAILED
  2. 二叉树的基本特性和二叉树的几种基本操作的机制_关于二叉树,你该了解这些!...
  3. 中超联赛提交函数的c语言,国家体育总局
  4. 【渗透过程】嘉缘网站 --测试
  5. 【转】PHP会话Session使用详解
  6. Vue插槽(solt)简单案例
  7. 从排列与组合的python实现到生日问题的解释
  8. 学习java_java学习册之立FLAG
  9. spring.xml
  10. 关于大型网站技术演进的思考(十三)--网站静态化处理—CSI(5)
  11. 【语音去噪】基于matlab GUI LMS+RLS语音去噪【含Matlab源码 528期】
  12. 【STC15】通过PWM波实现呼吸灯效果
  13. google hacking
  14. 赴微软 软件开发测试工程师。
  15. java中运行dos命令_JAVA中如何执行DOS命令
  16. 大豆技术面分析_大豆优质高产技术分析,种植大豆产量低,只因这几点你没做到...
  17. 数一段字母中各个字母的个数
  18. 安装project2016失败:Windows Installer和即点即用版本的Office程序不能并行
  19. ajax(java)
  20. IFE耀耀学院-表单总结

热门文章

  1. 腾讯,你妈喊你抄完作业回家吃饭
  2. 第七周作业——简单FTP
  3. selenium启动firefox时加载扩展
  4. 爱上MVC~Razor引擎时,在遍历中巧用Output.Write方法
  5. Android应用实现文件关联
  6. How ASP.NET MVC Works?
  7. javascript学习之void(0)的作用
  8. 电脑无法识别u盘怎么办_电脑无法识别U盘?5步操作让办公族轻松搞定!
  9. php业务网站资源网,企业创意业务网站模板
  10. 使用python 下载_使用python下载大量文件