yolov7 实现decode导出onnx

公版链接:

https://github.com/WongKinYiu/yolov7

修改后处理(抄yolov5),使得decode部分能够顺利解析

+    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()

+

+         #return x

+             self.grid[i], anchor_grid = self._make_grid(nx, ny, i)

+

+             y = x[i].sigmoid()

+             xy, wh, conf = y.split((2, 2, self.nc + 1), 4)  # y.tensor_split((2, 4, 5), 4)  # torch 1.8.0

+             xy = (xy * 2 + self.grid[i]) * self.stride[i]  # xy

+             wh = (wh * 2) ** 2 * anchor_grid  # wh

+             y = torch.cat((xy, wh, conf), 4)

+             z.append(y.view(bs, -1, self.no))

+         return torch.cat(z, 1)

+

+    def _make_grid(self, nx=20, ny=20, i=0):

+        d = self.anchors[i].device

+        t = self.anchors[i].dtype

+        shape = 1, self.na, ny, nx, 2  # grid shape

+        y, x = torch.arange(ny, device=d, dtype=t), torch.arange(nx, device=d, dtype=t)

+        yv, xv = torch.meshgrid(y, x)

+        grid = torch.stack((xv, yv), 2).expand(shape) - 0.5  # add grid offset, i.e. y = 2.0 * x - 0.5

+        anchor_grid = (self.anchors[i] * self.stride[i])

+        anchor_grid = anchor_grid.view((1, self.na, 1, 1, 2)).expand(shape)

+

+        return grid, anchor_grid
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值