- 相关参数改成自己的
- 注意输出的shape,onnx有时候会合并输出,目前不知道什么原因
import onnxruntime
import cv2, torch
import numpy as np
anchors=[[22, 55, 38, 44, 32, 88, 70, 56], [22, 22, 17, 35, 37, 24, 27, 34]]
ans=len(anchors[0])//2
cls_num=1
conf_th=0.25
nms_th=0.45
model_w=
model_h=
def get_boxes(output, anchors):
h=output.size(2)
w=output.size(3)
output=output.view(ans,int(cls_num+5),h,w).permute(0,2,3,1).contiguous()
conf = torch.sigmoid(output[..., 4])
cl = torch.sigmoid(output[..., 5:])
clv, cli = torch.max(cl, -1)
conf = conf * clv
mask = conf > conf_th
conf = conf[mask].unsqueeze(-1)
cli = cli[mask].unsqueeze(-1)
FloatTensor = torch.cuda.FloatTensor if conf.is_cuda else torch.FloatTensor
grid_h, grid_w = torch.meshgrid(torch.arange(h), torch.arange(w))
grid_h = grid_h.repeat(ans,1,1).type(FloatTensor)
grid_w = grid_w.repeat(ans,1,1).type(FloatTensor