- 转onnx时decode_in_inference是False,所以需要decode_outputs函数
- 需要注意的是,yolox的Exp中input_size和test_size是先高后宽,即(h,w)
import onnxruntime
import cv2, sys, torch, torchvision
import numpy as np
cls_num=3
conf_th=0.35
nms_th=0.45
model_w=640
model_h=352
ow=model_w/32
oh=model_h/32
def decode_outputs(outputs):
grids = []
strides = []
dtype=outputs.type()
for (hsize, wsize), stride in zip([(oh*4,ow*4),(oh*2,ow*2),(oh,ow)], [8, 16, 32]):
yv, xv = torch.meshgrid([torch.arange(hsize), torch.arange(wsize)])
grid = torch.stack((xv, yv), 2).view(1, -1, 2)
grids.append(grid)
shape = grid.shape[:2]
strides.append(torch.full((*shape, 1), stride))
grids