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

临沂哪里做网站企业网页页面模块

临沂哪里做网站,企业网页页面模块,大学生建设网站,建网站云空间前言 环境介绍: 1.编译环境 Ubuntu 18.04.5 LTS 2.RKNN版本 py3.8-rknn2-1.4.0 3.单板 迅为itop-3568开发板 一、现象 采用yolov5训练并将pt转换为onnx,再将onnx采用py3.8-rknn2-1.4.0推理转换为rknn出现置信度大于1,并且图像乱框问题…

前言

环境介绍:

1.编译环境

Ubuntu 18.04.5 LTS

2.RKNN版本

py3.8-rknn2-1.4.0

3.单板

迅为itop-3568开发板


一、现象

采用yolov5训练并将pt转换为onnx,再将onnx采用py3.8-rknn2-1.4.0推理转换为rknn出现置信度大于1,并且图像乱框问题。
类似下面这样
在这里插入图片描述

二、解决

经过网上一顿查找发现是在将pt文件转化为onnx时对models/yolo.py的修改有问题。网上大部分的修改都是下面这种
models/yolo.py

def forward(self, x):z = []  # inference outputfor i in range(self.nl):x[i] = self.m[i](x[i])  # convreturn x# def forward(self, x):#     z = []  # inference output#     for i in range(self.nl):#         x[i] = self.m[i](x[i])  # conv        #         bs, _, ny, nx = x[i].shape  # x(bs,255,20,20) to x(bs,3,20,20,85)#         x[i] = x[i].view(bs, self.na, self.no, ny, nx).permute(0, 1, 3, 4, 2).contiguous()#         if not self.training:  # inference#             if self.dynamic or self.grid[i].shape[2:4] != x[i].shape[2:4]:#                 self.grid[i], self.anchor_grid[i] = self._make_grid(nx, ny, i)#             if isinstance(self, Segment):  # (boxes + masks)#                 xy, wh, conf, mask = x[i].split((2, 2, self.nc + 1, self.no - self.nc - 5), 4)#                 xy = (xy.sigmoid() * 2 + self.grid[i]) * self.stride[i]  # xy#                 wh = (wh.sigmoid() * 2) ** 2 * self.anchor_grid[i]  # wh#                 y = torch.cat((xy, wh, conf.sigmoid(), mask), 4)#             else:  # Detect (boxes only)#                 xy, wh, conf = x[i].sigmoid().split((2, 2, self.nc + 1), 4)#                 xy = (xy * 2 + self.grid[i]) * self.stride[i]  # xy#                 wh = (wh * 2) ** 2 * self.anchor_grid[i]  # wh#                 y = torch.cat((xy, wh, conf), 4)#             z.append(y.view(bs, self.na * nx * ny, self.no))#     return x if self.training else (torch.cat(z, 1),) if self.export else (torch.cat(z, 1), x)

这是导致问题的根源,至于为什么现在我还没办法回答。正确的应该按如下方式修改

models/yolo.py

def forward(self, x):z = []  # inference outputfor i in range(self.nl):if os.getenv('RKNN_model_hack', '0') != '0':x[i] = torch.sigmoid(self.m[i](x[i]))  # convreturn x
# def forward(self, x):
#     z = []  # inference output
#     for i in range(self.nl):
#         x[i] = self.m[i](x[i])  # conv
#         bs, _, ny, nx = x[i].shape  # x(bs,255,20,20) to x(bs,3,20,20,85)
#         x[i] = x[i].view(bs, self.na, self.no, ny, nx).permute(0, 1, 3, 4, 2).contiguous()
#
#         if not self.training:  # inference
#             if self.grid[i].shape[2:4] != x[i].shape[2:4] or self.onnx_dynamic:
#                 self.grid[i] = self._make_grid(nx, ny).to(x[i].device)
#
#             y = x[i].sigmoid()
#             if self.inplace:
#                 y[..., 0:2] = (y[..., 0:2] * 2. - 0.5 + self.grid[i]) * self.stride[i]  # xy
#                 y[..., 2:4] = (y[..., 2:4] * 2) ** 2 * self.anchor_grid[i]  # wh
#             else:  # for YOLOv5 on AWS Inferentia https://github.com/ultralytics/yolov5/pull/2953
#                 xy = (y[..., 0:2] * 2. - 0.5 + self.grid[i]) * self.stride[i]  # xy
#                 wh = (y[..., 2:4] * 2) ** 2 * self.anchor_grid[i].view(1, self.na, 1, 1, 2)  # wh
#                 y = torch.cat((xy, wh, y[..., 4:]), -1)
#             z.append(y.view(bs, -1, self.no))
#
#     return x if self.training else (torch.cat(z, 1), x)

export.py文件的run函数

# shape = tuple((y[0] if isinstance(y, tuple) else y).shape)  # model output shape
shape = tuple(y[0].shape)  # model output shape

export.py文件的开头加上

#onn转换添加内容
import os
os.environ['RKNN_model_hack'] = 'npu_2'
#

修改之后按照如下命令导出onnx
其中./runs/train/exp3/weights/best.pt换成自己训练的pt文件

python export.py --weights ./runs/train/exp3/weights/best.pt --img 640 --batch 1 --include onnx --opset 12

参考这位大佬的文件

http://www.yayakq.cn/news/404519/

相关文章:

  • 网站正在建设中 页面建设网站的价钱
  • 投简历网站wordpress移除评论
  • 帮客户做网站 没签合同咋办水果电商网站建设相关文献
  • 景德镇建设局网站高端网络推广
  • 六安服装网站建设地址wordpress 神箭手
  • 排名app通州优化公司
  • 做网站动态背景的图片网站设计站点管理
  • 宜春建设网站公司竞价推广怎么样
  • 贾汪区建设局网站wordpress更换主题 小工具
  • 免费行情软件网站大全网页版西丽做网站
  • 营销型网站建设的一般过程包括哪些环节?南昌网站排名优化报
  • seo排名网站 优帮云wordpress使用教程书
  • 在线购物网站建设的需求分析武夷山网站建设
  • 网站服务器放置地怎么填写店铺设计思路及创意
  • 广东省做网站推广公司wordpress 评论ip拉黑
  • 做室内设计的网站小店网站怎么做
  • 专业公司网站建设服务公司上海专业做网站较好的公司
  • 网站建设多少钱鞋徐州百姓网招聘信息网
  • html5 图片网站无锡微盟网络科技有限公司
  • 阿里云做网站电话手机网站 图标
  • 企业微信网站开发文档wordpress 重置管理员密码
  • 长沙网站建设0731aso排名
  • 查建设施工资质的网站安装失败未能找到wordpress目录
  • 网站建设最难的是什么域名一般在哪里购买
  • 泉州网站建设服务电脑iis做网站
  • 东莞模板建站哪家好网站可以做无形资产
  • 建设信用卡网站换积分舟山网站建设有限公司
  • 做外贸网站进行销售 需要纳税吗wordpress说明书
  • 国内适合个人做外贸的网站有哪些呼市网页制作培训
  • 北京做网站源代码的商城网站验收