yolo转rknn推理置信度大于1出现乱框怎么解决

使用yolov5-5.0版本,导出时修改了yolo.py文件中的forward如下,opset设置12可是推理结果完全不对,请大佬解惑。

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.onnx_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)
        #
        #     y = x[i].sigmoid()
        #     if self.inplace:
        #         y[..., 0:2] = (y[..., 0:2] * 2 + 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, 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 * self.anchor_grid[i]  # wh
        #         y = torch.cat((xy, wh, conf), 4)
        #     z.append(y.view(bs, -1, self.no))

    return x #if self.training else (torch.cat(z, 1),) if self.export else (torch.cat(z, 1), x)

你可能感兴趣的:(python)