YOLOv5-7.0 后处理 解析

发布时间 2023-06-02 18:23:43作者: cold_moon

问题1: 怎么算输出的维度?

方法1:我们可以直接导出 pt 为 onnx 文件,使用 Netron 来看即可。

python export.py --weights yolov5s.pt --include  onnx --simplify
# --simplify 帮助我们看每个维度是多少。

方法2:手工计算

假设输入是 640*480( w, h )。假设有 3个 head,最大下采样为 32 倍,那么 640/32 = 20, 480/32 = 15, 85 为 (x,y,w,h,confidence, 80个类)。

所以,最后的特征图降为 20*15, 40*30, 80*60。 3 表示 每个 特征图上的 点 有 3 个 anchor,那么就有 3 个 预测框。

如果 batchsize=1,那么输出就有:

1*3*20*15*85, 1*3*40*30*85, 1*3*80*60*85
-> 1*900*85, 1*3600*85, 1*14400*85,

我们在 维度1 Concat 后为 1*18900*85。

问题:为什么可以直接 Concat?

因为:这些框已经还原为原图的坐标上面了。 模型本来输出的 tx,ty,tw,th 已经变为了 输入图像坐标下的 bx,by,bw,bh 了。因此后面直接对该 结果 1*18900*85(bx,by,bw,bh) 做 NMS 即可得到最后的检测结果。

image

后处理:

【1】https://blog.csdn.net/zhuguiqin1/article/details/122739044

【2】https://flyfish.blog.csdn.net/article/details/127265913

【3】https://flyfish.blog.csdn.net/article/details/119177472

【4】https://blog.csdn.net/lzzzzzzm/article/details/120151155