当前位置: 首页 > 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/196977/

相关文章:

  • 京东网站项目建设规划书公众号开发网站公司
  • 太原网站建设模板淘宝网站建设可行性分析报告
  • 网站模板如何修改域名wordpress 页面分栏
  • 深圳网站建设首选上榜网络物联网平台是干什么的用的
  • 网站首页排名下降滁州市建设工程协会网站
  • 网站域名和网址wordpress英文主题怎么用
  • 一个购物网站多少钱长春互联网推广
  • 在什么网站能找到做外贸的邮箱东莞百度seo新网站快速排名
  • 新手怎样做网站推广西安做网站 好运网络
  • 做论坛网站赚钱吗湖南常德市
  • 网站国际网络备案号网站开发中 敬请期待
  • 域名网站搭建wordpress 盒模型大学
  • 家用电脑和宽带做网站长沙网站建设公司排行榜
  • py做网站合肥网络推广技巧
  • 网站效果用什么软件做中国十大关键词
  • 快速建企业网站wordpress 音乐下载主题
  • 有可以做推广的网站吗莱芜民生网
  • 台州网站建设策划网站做换肤
  • 网站备案号怎么放佛山网站建设哪家效果好
  • 国内外知名提供邮箱服务的网站国外免费服务器地址
  • 淮南房地产网站建设网站惠安县住房和城乡建设部网站
  • 用wordpress建立专业网站视频教程海南住房与城乡建设部网站
  • 怎样用记事本做网站中国黄页
  • 注册网站名字怎么自己制作二维码
  • 定制网站建设多少钱app商城开发价格
  • 做网站的不给源文件wordpress账号admin
  • 网站建设 h5网站后台密码怎么改
  • 中国室内设计师联盟网站合肥做网站设计
  • 番禺外贸型网站建设河南平台网站建设价位
  • 网站流量降低关键词排名seo