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

西安政府部门政府网站建设服务商推文关键词生成器

西安政府部门政府网站建设服务商,推文关键词生成器,上海突发新闻,邯郸网站建设选哪家编辑:OAK中国 首发:oakchina.cn 喜欢的话,请多多👍⭐️✍ 内容可能会不定期更新,官网内容都是最新的,请查看首发地址链接。 ▌前言 Hello,大家好,这里是OAK中国,我是助手…

编辑:OAK中国
首发:oakchina.cn
喜欢的话,请多多👍⭐️✍
内容可能会不定期更新,官网内容都是最新的,请查看首发地址链接。

▌前言

Hello,大家好,这里是OAK中国,我是助手君。

最近咱社群里有几个朋友在将yolox转换成blob的过程有点不清楚,所以我就写了这篇博客。(请夸我贴心!咱的原则:合理要求,有求必应!)

1.其他Yolo转换及使用教程请参考
2.检测类的yolo模型建议使用在线转换(地址),如果在线转换不成功,你再根据本教程来做本地转换。

.pt 转换为 .onnx

使用下列脚本(将脚本放到 YOLOv8 根目录中)将 pytorch 模型转换为 onnx 模型,若已安装 openvino_dev,则可进一步转换为 OpenVINO 模型:

示例用法:

python export_onnx.py -w <path_to_model>.pt -imgsz 640 

export_onnx.py :

#!/usr/bin/env python3
# -*- coding:utf-8 -*-
import argparse
import json
import math
import subprocess
import sys
import time
import warnings
from pathlib import Pathimport onnx
import torch
import torch.nn as nnwarnings.filterwarnings("ignore")ROOT = Path.cwd()
if str(ROOT) not in sys.path:sys.path.append(str(ROOT))from ultralytics.nn.modules import Detect
from ultralytics.nn.tasks import attempt_load_weights
from ultralytics.yolo.utils import LOGGERclass DetectV8(nn.Module):"""YOLOv8 Detect head for detection models"""dynamic = False  # force grid reconstructionexport = False  # export modeshape = Noneanchors = torch.empty(0)  # initstrides = torch.empty(0)  # initdef __init__(self, old_detect):super().__init__()self.nc = old_detect.nc  # number of classesself.nl = old_detect.nl  # number of detection layersself.reg_max = (old_detect.reg_max)  # DFL channels (ch[0] // 16 to scale 4/8/12/16/20 for n/s/m/l/x)self.no = old_detect.no  # number of outputs per anchorself.stride = old_detect.stride  # strides computed during buildself.cv2 = old_detect.cv2self.cv3 = old_detect.cv3self.dfl = old_detect.dflself.f = old_detect.fself.i = old_detect.idef forward(self, x):shape = x[0].shape  # BCHWfor i in range(self.nl):x[i] = torch.cat((self.cv2[i](x[i]), self.cv3[i](x[i])), 1)box, cls = torch.cat([xi.view(shape[0], self.no, -1) for xi in x], 2).split((self.reg_max * 4, self.nc), 1)box = self.dfl(box)cls_output = cls.sigmoid()# Get the maxconf, _ = cls_output.max(1, keepdim=True)# Concaty = torch.cat([box, conf, cls_output], axis=1)# Split to 3 channelsoutputs = []start, end = 0, 0for i, xi in enumerate(x):end += xi.shape[-2] * xi.shape[-1]outputs.append(y[:, :, start:end].view(xi.shape[0], -1, xi.shape[-2], xi.shape[-1]))start += xi.shape[-2] * xi.shape[-1]return outputsdef bias_init(self):# Initialize Detect() biases, WARNING: requires stride availabilitym = self  # self.model[-1]  # Detect() modulefor a, b, s in zip(m.cv2, m.cv3, m.stride):  # froma[-1].bias.data[:] = 1.0  # boxb[-1].bias.data[: m.nc] = math.log(5 / m.nc / (640 / s) ** 2)  # cls (.01 objects, 80 classes, 640 img)if __name__ == "__main__":parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)parser.add_argument("-w", "--weights", type=Path, default="./yolov8s.pt", help="weights path")parser.add_argument("-imgsz","--img-size",nargs="+",type=int,default=[640, 640],help="image size",)  # height, widthparser.add_argument("--opset", type=int, default=12, help="opset version")args = parser.parse_args()args.img_size *= 2 if len(args.img_size) == 1 else 1  # expandLOGGER.info(args)t = time.time()# Check devicedevice = torch.device("cpu")# Load PyTorch modelmodel = attempt_load_weights(str(args.weights), device=device, inplace=True, fuse=True)  # load FP32 modellabels = (model.module.names if hasattr(model, "module") else model.names)  # get class nameslabels = labels if isinstance(labels, list) else list(labels.values())# check num classes and labelsassert model.nc == len(labels), f"Model class count {model.nc} != len(names) {len(labels)}"# Replace with the custom Detection Headif isinstance(model.model[-1], (Detect)):model.model[-1] = DetectV8(model.model[-1])num_branches = model.model[-1].nl# Inputimg = torch.zeros(1, 3, *args.img_size).to(device)  # image size(1,3,320,192) iDetection# Update modelmodel.eval()# ONNX exporttry:LOGGER.info("\nStarting to export ONNX...")output_list = [f"output{i+1}_yolov6r2" for i in range(num_branches)]export_file = args.weights.with_suffix(".onnx")  # filenametorch.onnx.export(model,img,export_file,verbose=False,opset_version=args.opset,training=torch.onnx.TrainingMode.EVAL,do_constant_folding=True,input_names=["images"],output_names=output_list,dynamic_axes=None,)# Checksonnx_model = onnx.load(export_file)  # load onnx modelonnx.checker.check_model(onnx_model)  # check onnx modeltry:import onnxsimLOGGER.info("\nStarting to simplify ONNX...")onnx_model, check = onnxsim.simplify(onnx_model)assert check, "assert check failed"except Exception as e:LOGGER.warning(f"Simplifier failure: {e}")LOGGER.info(f"ONNX export success, saved as {export_file}")except Exception as e:LOGGER.error(f"ONNX export failure: {e}")export_json = export_file.with_suffix(".json")export_json.with_suffix(".json").write_text(json.dumps({"anchors": [],"anchor_masks": {},"coordinates": 4,"labels": labels,"num_classes": model.nc,},indent=4,))LOGGER.info("Labels data export success, saved as %s" % export_json)# OpenVINO exportprint("\nStarting to export OpenVINO...")export_dir = Path(str(export_file).replace(".onnx", "_openvino"))OpenVINO_cmd = ("mo --input_model %s --output_dir %s --data_type FP16 --scale 255 --reverse_input_channel --output '%s' "% (export_file, export_dir, ",".join(output_list)))try:subprocess.check_output(OpenVINO_cmd, shell=True)LOGGER.info(f"OpenVINO export success, saved as {export_dir}")except Exception as e:LOGGER.warning(f"OpenVINO export failure: {e}")LOGGER.info("\nBy the way, you can try to export OpenVINO use:")LOGGER.info("\n%s" % OpenVINO_cmd)# OAK Blob exportLOGGER.info("\nThen you can try to export blob use:")export_xml = export_dir / export_file.with_suffix(".xml")export_blob = export_dir / export_file.with_suffix(".blob")blob_cmd = ("compile_tool -m %s -ip U8 -d MYRIAD -VPU_NUMBER_OF_SHAVES 6 -VPU_NUMBER_OF_CMX_SLICES 6 -o %s"% (export_xml, export_blob))LOGGER.info("\n%s" % blob_cmd)# FinishLOGGER.info("\nExport complete (%.2fs)" % (time.time() - t))

可以使用 Netron 查看模型结构:

在这里插入图片描述

▌转换

openvino 本地转换

onnx -> openvino

mo 是 openvino_dev 2022.1 中脚本,

安装命令为 pip install openvino-dev

mo --input_model yolov8n.onnx --scale 255 --reverse_input_channel

openvino -> blob

<path>/compile_tool -m yolov8n.xml \
-ip U8 -d MYRIAD \
-VPU_NUMBER_OF_SHAVES 6 \
-VPU_NUMBER_OF_CMX_SLICES 6

在线转换

blobconvert 网页 http://blobconverter.luxonis.com/

  • 进入网页,按下图指示操作:

在这里插入图片描述

  • 修改参数,转换模型:

在这里插入图片描述

  1. 选择 onnx 模型
  2. 修改 optimizer_params--data_type=FP16 --scale 255 --reverse_input_channel
  3. 修改 shaves6
  4. 转换

blobconverter python 代码

blobconverter.from_onnx("yolov8n.onnx",	optimizer_params=["--scale 255","--reverse_input_channel",],shaves=6,)

blobconvert cli

blobconverter --onnx yolov8n.onnx -sh 6 -o . --optimizer-params "scale=255 --reverse_input_channel"

▌DepthAI 示例

正确解码需要可配置的网络相关参数:

  • setNumClasses - YOLO 检测类别的数量
  • setIouThreshold - iou 阈值
  • setConfidenceThreshold - 置信度阈值,低于该阈值的对象将被过滤掉
import cv2
import depthai as dai
import numpy as npmodel = dai.OpenVINO.Blob("yolov8n.blob")
dim = model.networkInputs.get("images").dims
W, H = dim[:2]
labelMap = [# "class_1","class_2","...""class_%s"%i for i in range(80)
]# Create pipeline
pipeline = dai.Pipeline()# Define sources and outputs
camRgb = pipeline.create(dai.node.ColorCamera)
detectionNetwork = pipeline.create(dai.node.YoloDetectionNetwork)
xoutRgb = pipeline.create(dai.node.XLinkOut)
nnOut = pipeline.create(dai.node.XLinkOut)xoutRgb.setStreamName("rgb")
nnOut.setStreamName("nn")# Properties
camRgb.setPreviewSize(W, H)
camRgb.setResolution(dai.ColorCameraProperties.SensorResolution.THE_1080_P)
camRgb.setInterleaved(False)
camRgb.setColorOrder(dai.ColorCameraProperties.ColorOrder.BGR)
camRgb.setFps(40)# Network specific settings
detectionNetwork.setBlob(model)
detectionNetwork.setConfidenceThreshold(0.5)
detectionNetwork.setNumClasses(80)
detectionNetwork.setCoordinateSize(4)
detectionNetwork.setAnchors([])
detectionNetwork.setAnchorMasks({})
detectionNetwork.setIouThreshold(0.5)# Linking
camRgb.preview.link(detectionNetwork.input)
camRgb.preview.link(xoutRgb.input)
detectionNetwork.out.link(nnOut.input)# Connect to device and start pipeline
with dai.Device(pipeline) as device:# Output queues will be used to get the rgb frames and nn data from the outputs defined aboveqRgb = device.getOutputQueue(name="rgb", maxSize=4, blocking=False)qDet = device.getOutputQueue(name="nn", maxSize=4, blocking=False)frame = Nonedetections = []color2 = (255, 255, 255)# nn data, being the bounding box locations, are in <0..1> range - they need to be normalized with frame width/heightdef frameNorm(frame, bbox):normVals = np.full(len(bbox), frame.shape[0])normVals[::2] = frame.shape[1]return (np.clip(np.array(bbox), 0, 1) * normVals).astype(int)def displayFrame(name, frame):color = (255, 0, 0)for detection in detections:bbox = frameNorm(frame, (detection.xmin, detection.ymin, detection.xmax, detection.ymax))cv2.putText(frame, labelMap[detection.label], (bbox[0] + 10, bbox[1] + 20), cv2.FONT_HERSHEY_TRIPLEX, 0.5, 255)cv2.putText(frame, f"{int(detection.confidence * 100)}%", (bbox[0] + 10, bbox[1] + 40), cv2.FONT_HERSHEY_TRIPLEX, 0.5, 255)cv2.rectangle(frame, (bbox[0], bbox[1]), (bbox[2], bbox[3]), color, 2)# Show the framecv2.imshow(name, frame)while True:inRgb = qRgb.tryGet()inDet = qDet.tryGet()if inRgb is not None:frame = inRgb.getCvFrame()if inDet is not None:detections = inDet.detectionsif frame is not None:displayFrame("rgb", frame)if cv2.waitKey(1) == ord('q'):break

▌参考资料

https://www.oakchina.cn/2023/02/24/yolov8-blob/
https://docs.oakchina.cn/en/latest/
https://www.oakchina.cn/selection-guide/


OAK中国
| OpenCV AI Kit在中国区的官方代理商和技术服务商
| 追踪AI技术和产品新动态

戳「+关注」获取最新资讯↗↗


文章转载自:
http://montadale.wwxg.cn
http://leadswinging.wwxg.cn
http://unclear.wwxg.cn
http://paginary.wwxg.cn
http://earthpea.wwxg.cn
http://hystrichosphere.wwxg.cn
http://forehock.wwxg.cn
http://tweed.wwxg.cn
http://blob.wwxg.cn
http://penniform.wwxg.cn
http://motard.wwxg.cn
http://liverwurst.wwxg.cn
http://accountable.wwxg.cn
http://biodynamics.wwxg.cn
http://canna.wwxg.cn
http://attenuator.wwxg.cn
http://appd.wwxg.cn
http://diablo.wwxg.cn
http://uptake.wwxg.cn
http://bushtailed.wwxg.cn
http://nomistic.wwxg.cn
http://encouraged.wwxg.cn
http://midshipman.wwxg.cn
http://cubature.wwxg.cn
http://anthropometric.wwxg.cn
http://bacterin.wwxg.cn
http://vendition.wwxg.cn
http://hand.wwxg.cn
http://shick.wwxg.cn
http://illimitably.wwxg.cn
http://insufflate.wwxg.cn
http://culpability.wwxg.cn
http://limbus.wwxg.cn
http://thermoset.wwxg.cn
http://madbrain.wwxg.cn
http://pinnace.wwxg.cn
http://industrious.wwxg.cn
http://alcoran.wwxg.cn
http://ringingly.wwxg.cn
http://technocrat.wwxg.cn
http://extralunar.wwxg.cn
http://lykewake.wwxg.cn
http://passport.wwxg.cn
http://mutably.wwxg.cn
http://fluidextract.wwxg.cn
http://firewater.wwxg.cn
http://strucken.wwxg.cn
http://nitromannitol.wwxg.cn
http://gyrostabilized.wwxg.cn
http://sacher.wwxg.cn
http://purgee.wwxg.cn
http://desaturate.wwxg.cn
http://btm.wwxg.cn
http://toff.wwxg.cn
http://lustily.wwxg.cn
http://samoyedic.wwxg.cn
http://convex.wwxg.cn
http://bio.wwxg.cn
http://marxism.wwxg.cn
http://transudation.wwxg.cn
http://exoticism.wwxg.cn
http://electrohorticulture.wwxg.cn
http://intolerability.wwxg.cn
http://walkabout.wwxg.cn
http://abe.wwxg.cn
http://neuropsychic.wwxg.cn
http://isopolity.wwxg.cn
http://preoccupation.wwxg.cn
http://birdbath.wwxg.cn
http://dejectile.wwxg.cn
http://socialise.wwxg.cn
http://washwoman.wwxg.cn
http://unifilar.wwxg.cn
http://preclude.wwxg.cn
http://online.wwxg.cn
http://yokeropes.wwxg.cn
http://sonography.wwxg.cn
http://gasper.wwxg.cn
http://fakery.wwxg.cn
http://semiprivate.wwxg.cn
http://emplastic.wwxg.cn
http://garibaldist.wwxg.cn
http://slumber.wwxg.cn
http://biyearly.wwxg.cn
http://flitty.wwxg.cn
http://allecret.wwxg.cn
http://panorama.wwxg.cn
http://waltz.wwxg.cn
http://hqmc.wwxg.cn
http://templet.wwxg.cn
http://bisk.wwxg.cn
http://brutishly.wwxg.cn
http://lambie.wwxg.cn
http://countercheck.wwxg.cn
http://subopposite.wwxg.cn
http://heptanone.wwxg.cn
http://keet.wwxg.cn
http://borrower.wwxg.cn
http://sweepstakes.wwxg.cn
http://boulogne.wwxg.cn
http://www.hrbkazy.com/news/68763.html

相关文章:

  • 阿里巴巴网站怎么做郑州网站运营
  • 阿里云备案成功怎么建设网站最新足球消息
  • 手机可以搭建网站吗黑帽seo论坛
  • 做企业网站备案收费吗网站快速排名服务
  • 快三网站建设百度推广账户优化方案
  • 美团是最早做团购的网站么开网店怎么推广运营
  • 外贸网站制作方案河南新闻头条最新消息
  • 邯郸专业网站建设公司网络营销外包推广
  • 汶上网站制作临沧seo
  • 服务器网站环境网站优化公司哪家效果好
  • 新疆生产建设兵团科技局网站网站秒收录
  • 云服务器可以用来做网站么市场调研报告模板ppt
  • 镇江网站推广优化营商环境条例解读
  • 平面设计师常用网站建站之星官网
  • 营销型网站套餐网络营销的策略包括
  • 销售网站免费模板关键词难易度分析
  • 新昌县住房和城乡建设局网站如何创建公司网站
  • 精品课程网站建设方案朋友圈推广怎么收费
  • 怎样用wordpress建站最近有哪些新闻
  • 上海电子商务网站seo公司推荐
  • 企业网站制作公司推荐系统优化软件
  • php网站怎么做后台管理开封网络推广哪家好
  • wordpress导航类网站兰州seo外包公司
  • 为知笔记 编辑wordpress网站推广优化排名
  • 做婚礼请柬的网站有哪些google play 应用商店
  • 凡客建站登录入口如何做网站平台
  • wordpress 破解后台网站seo技术教程
  • 做炫舞情侣头像动态图网站谷歌地图下载
  • 企业网站网页设计的步骤湖南网站seo地址
  • 无锡新区企业网站推广软广告经典案例