当前位置: 首页 > news >正文

泉州建设银行网站来广营做网站公司

泉州建设银行网站,来广营做网站公司,静态网站 服务器,光谷做网站推广哪家好一、openvino安装 参看官方文档https://www.intel.com/content/www/us/en/developer/tools/openvino-toolkit/download.html 安装命令是根据上面的选择生成。这里安装了pytorch和onnx依赖。 二、pytorch模型转opnvino模型推理 import os import time import cv2 import nu…

一、openvino安装

参看官方文档https://www.intel.com/content/www/us/en/developer/tools/openvino-toolkit/download.html
在这里插入图片描述
在这里插入图片描述
安装命令是根据上面的选择生成。这里安装了pytorch和onnx依赖。

二、pytorch模型转opnvino模型推理

import os
import time
import cv2
import numpy as np
import torchfrom openvino.runtime import Core
from openvino.tools import moimg_path = r'./000000002306.jpg'
model_path = 'pure_pose.pt'
## 加载onnx模型
model = torch.load(model_path)
model.eval()
## onnx模型转openvino
model_ir = mo.convert_model(model, input_shape=[1,3, 256, 192],mean_values = [123.675, 116.28 , 103.53],scale_values=[58.395, 57.12 , 57.375],compress_to_fp16=True
)## 图片预处理
image = cv2.cvtColor(src=cv2.imread(filename=str(img_path)),code=cv2.COLOR_BGR2RGB,
)
resized_image,ratio, (dw, dh) = letterbox(image,new_shape=(256,192))# # # Convert the image shape to a shape and a data type expected by the network
# # # for OpenVINO IR model: (1, 3, 512, 512).
input_image = np.expand_dims(np.transpose(resized_image, (2, 0, 1)), 0)ie = Core()
compiled_model_ir = ie.compile_model(model=model_ir, device_name="CPU")
# Get the names of input and output layers.
input_layer_ir = compiled_model_ir.input(0)
output_layer_ir = compiled_model_ir.output(0)# Do inference on the input image.
start_time = time.perf_counter()
result = compiled_model_ir([input_image])[output_layer_ir]
end_time = time.perf_counter()
print(f"Inference finished. Inference time: {end_time-start_time:.3f} seconds, "f"FPS: {1/(end_time-start_time):.2f}."
)

在pytorch转openvino模型的时候,已包含归一化操作过程。在推理的时候不需要对输入图片做归一化操作。

三、onnx模型转opnvino模型推理

1. onnx模型转openvino模型

在上面的安装文件夹openvino_env文件夹下找到mo_onnx.py文件。我的路径:openvino_env/lib/python3.9/site-packages/openvino/tools/mo/mo_onnx.py
根据下面的脚本将onnx模型转成openvino模型

python ../openvino_env/lib/python3.9/site-packages/openvino/tools/mo/mo_onnx.py \--input_model ./mobilenet_load.onnx  \--output_dir ./openvino_model \--input_shape "[1,3,256,192]" \--mean_values="[123.675, 116.28 , 103.53]" \--scale_values="[58.395, 57.12 , 57.375]" \--data_type FP16

生成下面三个文件
在这里插入图片描述

2. 调用openvino模型进行推理

import time
import cv2
import numpy as np
from openvino.runtime import Core
img_path = r'./000000002306.jpg'
from utils import letterboximage = cv2.cvtColor(cv2.imread(img_path), cv2.COLOR_BGR2RGB)# Convert the resized images to network input shape
resized_image,ratio, (dw, dh) = letterbox(image,new_shape=(256,192))
h, w, c = resized_image.shape
input_image = np.expand_dims(np.transpose(resized_image, (2, 0, 1)), 0)# Load the network in Inference Engine
core = Core()
model_ir = core.read_model(model="openvino_model/mobilenet_load.xml")
compiled_model_ir = core.compile_model(model=model_ir, device_name="CPU")# Get output layer
output_layer_ir = compiled_model_ir.output(0)# Run inference on the input image
# Do inference on the input image.
start_time = time.perf_counter()
res_ir = compiled_model_ir([input_image])[output_layer_ir]
end_time = time.perf_counter()
print(f"Inference finished. Inference time: {end_time-start_time:.3f} seconds, "f"FPS: {1/(end_time-start_time):.2f}."
)

比较通过pytorch和onnx转成的openvino模型的推理时间,差不多。openvino模型推理时间大概是pytorch模型推理时间的1/5.

模型推理时间(s)
openvino0.010
onnx0.015
pytorch0.048
http://www.yayakq.cn/news/877449/

相关文章:

  • 古建设工程造价管理协会网站做网站改变图片位置
  • 网站设计遇到难题软件开发工程师考核指标
  • 济南做外贸的网站公司吗单页设计图片
  • 上海十大网站建设用户界面设计的三大原则
  • 触屏网站开发教程网站维护工程师工资
  • 有了网站源码 怎么建设网站建设一个打鱼游戏网站
  • 长沙会议网站设计哪家专业自己怎么做外贸英文网站
  • 如何进行营销型企业网站的优化推荐广东中山网站建设
  • 顺义公司建站多少钱北京专业网站建设
  • wordpress 头像加速网站seo排名优化工具在线
  • 高端建站网站设计 趋势
  • 一键建站免费钓鱼网站的危害
  • 崇明专业做网站常熟滨江开发区人才网
  • 腾讯云wed服务器做网站wordpress 元素用处
  • 物流企业网站模板下载网站运营管理主要内容
  • 网站pv是什么意思高明网站设计
  • 一级A视网站 一级做爰片大连网站如何制作
  • 免费网站推广网站破解版学php网站开发多钱
  • 互联网站的建设维护营销建设网站一般过程
  • 网站建设话术关键词做网站的收费
  • 做资源的教育类网站或公司竞价单页制作
  • 学生兼职做网站自己的网站怎么做搜索引擎
  • 巩义做网站汉狮公司建网站要租服务器吗
  • 做3d ppt模板下载网站有哪些网站建设优化之优化关键字
  • 有多少网站是做废旧信息的北京seo排名公司
  • 信息网站 模板免费域名空间国外
  • 发布信息免费的网站三维制图培训班在哪里
  • 东方城乡与住房建设部网站网络规划设计师报名
  • 巢湖自助建站系统平度做网站
  • 网站建设情况报告网站建设的生存期模型