yolov5不能检测长宽比超过20的目标的解决方法

网友投稿 1021 2022-08-31

yolov5不能检测长宽比超过20的目标的解决方法

yolov5不能检测长宽比超过20的目标的解决方法

最近在使用YOLOv5代码的时候,发现yolov5对长宽比很大,如超过100+的目标检测,完全检测不出来, 之前一直怀疑是anchors设置有问题,验证了很多次,证明不是anchors的问题,

最后经组内小伙伴提醒,yolov5在数据增强的时候,默认设置了目标的长宽比最大为20,需要修改的文件(utils/datasets.py)

def box_candidates(box1, box2, wh_thr=2, ar_thr=20, area_thr=0.1, special_classes=0): # box1(4,n), box2(4,n) # Compute candidate boxes: box1 before augment, box2 after augment, wh_thr (pixels), aspect_ratio_thr, area_ratio w1, h1 = box1[2] - box1[0], box1[3] - box1[1] w2, h2 = box2[2] - box2[0], box2[3] - box2[1] ar = np.maximum(w2 / (h2 + 1e-16), h2 / (w2 + 1e-16)) # aspect ratio return (w2 > wh_thr) & (h2 > wh_thr) & (w2 * h2 / (w1 * h1 + 1e-16) > area_thr) & (ar < ar_thr) # candidates

修改为:

def box_candidates(box1, box2, wh_thr=2, ar_thr=20, area_thr=0.1, special_classes=0): # box1(4,n), box2(4,n) # Compute candidate boxes: box1 before augment, box2 after augment, wh_thr (pixels), aspect_ratio_thr, area_ratio w1, h1 = box1[2] - box1[0], box1[3] - box1[1] w2, h2 = box2[2] - box2[0], box2[3] - box2[1] ar = np.maximum(w2 / (h2 + 1e-16), h2 / (w2 + 1e-16)) # aspect ratio return (w2 > wh_thr) & (h2 > wh_thr) & (w2 * h2 / (w1 * h1 + 1e-16) > area_thr) & ((ar < ar_thr) | ((special_classes==0) and (ar < 120))) #candidates

其中 special_classes为长宽比最大的类别,因为长宽比最大为 105,所以设置了ar<120

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:LabelingPixelFromImage
下一篇:go build命令(go语言编译命令)完全攻略(公务员报考条件)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~