OpenVINO工具套件使用教程

工具套件下载地址:
https://www.intel.com/content/www/us/en/developer/tools/openvino-toolkit/download.html
安装说明:
https://docs.openvino.ai/nightly/openvino_docs_install_guides_install_dev_tools.html

1.OpenVINO ™工具套件

OpenVINO工具包(ToolKit)主要包括两个核心组件,模型优化器(Model Optimizer)推理引擎(Inference Engine)

  • 模型优化器(Model Optimizer)将给定的模型转化为标准的 Intermediate Representation (IR) ,并对模型优化。
    模型优化器支持的深度学习框架:ONNX、TensorFlow、Caffe、MXNet、Kaldi
  • 推理引擎(Inference Engine)支持硬件指令集层面的深度学习模型加速运行,同时对传统的OpenCV图像处理库也进行了指令集优化,有显著的性能与速度提升。
    支持的硬件设备:CPU、GPU、FPGA、VPU

完整的工作流:
在这里插入图片描述

  • model:modeldownloader下载公共模型、open_model_zoo自带的模型或者自行训练
  • prepare_inference: 模型优化器,将模型转化为推理引擎需要的格式文件
  • benchmark: 性能因素与基准测试方法
  • select system: 选择正确的系统和操作硬件
  • decode density: 选择合适硬件的另一个因素是系统可支持多少个摄像头
  • full pipeline: 构建流水线进行测试
  • AI application:构建AI应用

使用实例:

模型优化器:将squeezenet1.1.caffemodel转化为IR格式

…\Intel\openvino_2021\deployment_tools\model_optimizer>

mo_caffe.py --input_model  ..\OV-200-lab-files\02\exercise-1\public\squeezenet1.1\squeezenet1.1.caffemodel  --output_dir ..\OV-200-lab-files\02\exercise-1\public\squeezenet1.1\
推理引擎:查看classification_sample_async.py文件并运行

…\Intel\openvino_2021\inference_engine\samples\python\classification_sample_async\classification_sample_async.py 把该文件复制到目标文件夹
…\OV-200-lab-files\02\exercise-1\public\squeezenet1.1>

python classification_sample_async.py -h
python classification_sample_async.py -i car.png -m squeezenet1.1.xml --labels squeezenet1.1.labels -d CPU
python classification_sample_async.py -i images/car.png -m squeezenet1.1.xml --labels squeezenet1.1.labels -d CPU
python classification_sample_async.py -i boy-computer.png -m squeezenet1.1.xml --labels squeezenet1.1.labels -d CPU
python classification_sample_async.py -i burger1.png -m squeezenet1.1.xml --labels squeezenet1.1.labels -d CPU
将squeezenet1.1.caffemodel替换为resnet-50.caffemodel重复上述两个操作
mo_caffe.py --input_model  ..\OV-200-lab-files\02\exercise-1\public\resnet-50\resnet-50.caffemodel  --output_dir ..\OV-200-lab-files\02\exercise-1\public\resnet-50\
python classification_sample_async.py -i car.png -m resnet-50.xml --labels resnet-50.labels -d CPU
python classification_sample_async.py -i boy-computer.jpg -m resnet-50.xml --labels resnet-50.labels -d CPU
python classification_sample_async.py -i burger.jpg -m resnet-50.xml --labels resnet-50.labels -d CPU

2. 深度学习与模型优化器详解

2.1. 模型优化器使用示例
安装模型优化器的必要组件
..\Intel\openvino_2021\deployment_tools\model_optimizer\install_prerequisites>install_prerequisites.bat

ERROR: Can not perform a ‘–user’ install. User site-packages are not visible in this virtualenv
解决:1) Go to the pyvenv.cfg file in the Virtual environment folder 2) Set the include-system-site-packages to true and save the change 3) Reactivate the virtual environment.

下载onnx/mobilenet文件

下载地址:https://github.com/onnx/models/blob/main/vision/classification/mobilenet/model/mobilenetv2-7.onnx

查看模型的说明文件
..\Intel\openvino_2021.4.752\deployment_tools\open_model_zoo\models\public\mobilenet-v2-pytorch\model.yml

相关信息:
framework: pytorch
conversion_to_onnx_args:
–model-name=mobilenet_v2
–weights=dl_dir/mobilenet_v2-b0353104.pth
–import-module=torchvision.models
–input-shape=1,3,224,224
–output-file=conv_dir/mobilenet-v2.onnx
–input-names=data
–output-names=prob
model_optimizer_args:
–input=data
–mean_values=data[123.675,116.28,103.53]
–scale_values=data[58.624,57.12,57.375]
–reverse_input_channels
–output=prob
–input_model=$conv_dir/mobilenet-v2.onnx

使用模型优化器

(venv) D:\guan\learning\intel\virtual\OV-200-lab-files\03\exercise-1>
D:\guan\learning\intel\virtual\OV-200-lab-files\venv\Lib\site-packages\mo.py --input_model mobilenetv2-7.onnx --mean_values=data[123.675,116.28,103.53] --scale_values=data[58.624,57.12,57.375] --reverse_input_channels --output_dir D:\guan\learning\intel\virtual\OV-200-lab-files\03\exercise-1

使用推理引擎对图片进行分类

python classification_sample_async.py -i images/1.jpeg -m mobilenetv2-7.xml --labels label.labels -d CPU

2.2. 使用模型优化器优化SSD-mobilenet模型

SSD 对图形中的对象进行检测和分类,并行搜索不同大小的对象,尝试对每个对象分类
##下载ssd_mobilenet_v2_coco
(venv) D:\guan\learning\intel\virtual\OV-200-lab-files\03\exercise-2>
python D:\guan\learning\intel\virtual\OV-200-lab-files\03\exercise-2\downloader.py --name ssd_mobilenet_v2_coco --output_dir D:\guan\learning\intel\virtual\OV-200-lab-files\03\exercise-2\

查看模型说明

model_optimizer_args:

  • –reverse_input_channels
  • –input_shape=[1,300,300,3]
  • –input=image_tensor
  • –transformations_config=$mo_dir/extensions/front/tf/ssd_v2_support.json
  • –tensorflow_object_detection_api_pipeline_config=$dl_dir/ssd_mobilenet_v2_coco_2018_03_29/pipeline.config
  • –output=detection_classes,detection_scores,detection_boxes,num_detections
  • –input_model=$dl_dir/ssd_mobilenet_v2_coco_2018_03_29/frozen_inference_graph.pb
使用模型优化器优化模型
..\OV-200-lab-files\venv\Lib\site-packages\mo.py --input_model D:\guan\learning\intel\virtual\OV-200-lab-files\03\exercise-2\public\ssd_mobilenet_v2_coco\ssd_mobilenet_v2_coco_2018_03_29\frozen_inference_graph.pb --reverse_input_channels --input_shape=[1,300,300,3] --input=image_tensor --transformations_config=..\OV-200-lab-files\03\exercise-2\ssd_v2_support.json --tensorflow_object_detection_api_pipeline_config=..\OV-200-lab-files\03\exercise-2\public\ssd_mobilenet_v2_coco\ssd_mobilenet_v2_coco_2018_03_29\pipeline.config --output=detection_classes,detection_scores,detection_boxes,num_detections --model_name ssd_mobilenet --output_dir ..\OV-200-lab-files\03\exercise-2\
使用模型检测对象
`python object_detection.py -m ssd_mobilenet.xml --labels labels.txt -i images/1.jpg`

###该步骤未成功AttributeError: ‘openvino.inference_engine.ie_api.IENetwork’ object has no attribute ‘layers’

3、深入了解:改变batches/change input shape/cut portions
creat batches
..\OV-200-lab-files\venv\Lib\site-packages\mo.py --input_model mobilenetv2-7.onnx --mean_values=data[123.675,116.28,103.53] --scale_values=data[58.624,57.12,57.375] --reverse_input_channels --output_dir ..\OV-200-lab-files\03\exercise-3 --batch 4 --model_name mobilenetv2-7_batch4
change input shape
..\OV-200-lab-files\venv\Lib\site-packages\mo.py --input_model mobilenetv2-7.onnx --mean_values=data[123.675,116.28,103.53] --scale_values=data[58.624,57.12,57.375] --reverse_input_channels --output_dir ..\OV-200-lab-files\03\exercise-3 --input_shape [1,3,100,100] --model_name mobilenetv2-7_shapemin
使用推理引擎
python classification_sample_async.py -i 1.jpeg -m mobilenetv2-7.xml --labels labels.txt -d CPU
python classification_sample_async.py -i 1.jpeg -m mobilenetv2-7_shapemin.xml --labels labels.txt -d CPU
cut portions & change format

3. 推理引擎

API文档:https://docs.openvino.ai/latest/api/ie_python_api/api.html

3.1. 使用api创建
ie = IECore()  
net = ie.read_network(model=model_xml, weights=model_bin)
exec_net = ie.load_network(network=net, device_name="CPU")
out=exec_net.infer({input_blob:image})

python hello_classification.py#运行
其他plugin:‘hetero’ ‘multi’
在这里插入图片描述

3.2. 获取系统中的可用设备及性能数据
devices=ie.available_devices
performance_counters = exec_net.requests[0].get_perf_counts()

4. 性能评估与硬件选型

4.1. 性能参数:

吞吐量及延迟、效率、神经网络的参数、目标设备、模型精度

4.2. 目标追踪实验:添加时间
time_start = time.time()
exec_net.start_async(request_id=next_request_id, inputs=feed_dict)
time_end=time.time()
inference_time=time_end-time_start
sys.stdout.write('%.5s'% inference_time)
4.3. 性能评估实践:benchmark使用

异步运行

python benchmark_app.py -i images/ -m models/resnet-50.xml 

在这里插入图片描述

python benchmark_app.py -i images/ -m models/ssd-mobilenet.xml

在这里插入图片描述

同步运行

python benchmark_app.py -i images/ -m models/ssd-mobilenet.xml --api sync

在这里插入图片描述

5 视频处理

5.1 运行多路视频的路人追踪示例
三个视频
python multi_camera_multi_person_tracking.py --m_detector models/person-detection-retail-0013.xml --m_reid models/person-reidentification-retail-0300.xml --config config.py -i Videos/video1.avi Videos/video2.avi Videos/video3.avi --no_show --output out.avi
一个视频
python multi_camera_multi_person_tracking.py --m_detector models/person-detection-retail-0013.xml --m_reid models/person-reidentification-retail-0300.xml --config config.py -i Videos/video1.avi  --output out.avi

6. 完整AI应用流程

了解需求后,选择正确的系统和操作硬件
工作流(视频处理流水线):解码、前处理、推理、后处理、编码
用DL-Streamer创建完整的视频处理流程

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值