WBF:检测任务NMS后虑框新方式?

举报
苏道 发表于 2022/06/29 17:52:06 2022/06/29
【摘要】 论文:Weighted boxes fusion: Ensembling boxes from different object detection models

论文:Weighted boxes fusion: Ensembling boxes from different object detection models

代码:https://link.zhihu.com/?target=https%3A//github.com/ZFTurbo/Weighted-Boxes-Fusion


前言

           最近在实际任务中,同个目标被多个同类框重复框选,这个毕竟不同框比例差距大,NMS无法覆盖这样的场景,可以看看下图

1.jpg

NMS和soft-NMS的方法都是排除框,不会改变框的值和新生成框,而WBF(Weighted Boxes Fusion)加权框融合,就是把框都加权融合成一个新的框,如下图所示,非常直观:

2.JPG


另外这个方案,可以直接

pip instal ensemble-boxes

这个包里包括了nms, soft_nms, non_maximun_weighted, weighted_boxed_fusion多个功能,非常好用。实测速度上,nms是远快于soft-nms。而这个ensemble-boxes存在两个问题:

1、boxes里的x1,y1,x2,y2需要归一化到[0:1]。

          执行归一化的操作是需要计算时间的,不高效,如果想不执行归一化的话,需要修改ensemble-boxes里的源码,对于nms和soft-nms方法,只需要注释掉ensemble_boxes_nms.py中的192行:

    # Fix coordinates and removed zero area boxes
    boxes, scores, labels = prepare_boxes(boxes, scores, labels)


2、ensemble-boxes的方法不会放回过滤后的indexs,而有的场景又需要怎么办??

         对于nms和soft-nms方法,修改ensemble_boxes_nms.py中205行开始,原始是:

        if method != 3:
            keep = cpu_soft_nms_float(boxes_by_label.copy(), scores_by_label.copy(), Nt=iou_thr, sigma=sigma, thresh=thresh, method=method)
        else:
            # Use faster function
            keep = nms_float_fast(boxes_by_label, scores_by_label, thresh=iou_thr)

        final_boxes.append(boxes_by_label[keep])
        final_scores.append(scores_by_label[keep])
        final_labels.append(labels_by_label[keep])
    final_boxes = np.concatenate(final_boxes)
    final_scores = np.concatenate(final_scores)
    final_labels = np.concatenate(final_labels)

      修改为, 即可:

        final_keep = []
        if method != 3:
            keep = cpu_soft_nms_float(boxes_by_label.copy(), scores_by_label.copy(), Nt=iou_thr, sigma=sigma, thresh=thresh, method=method)
        else:
            # Use faster function
            keep = nms_float_fast(boxes_by_label, scores_by_label, thresh=iou_thr)
        final_keep.append(keep)

        final_boxes.append(boxes_by_label[keep])
        final_scores.append(scores_by_label[keep])
        final_labels.append(labels_by_label[keep])
    final_boxes = np.concatenate(final_boxes)
    final_scores = np.concatenate(final_scores)
    final_labels = np.concatenate(final_labels)
    return final_boxes, final_scores, final_labels, final_keep


3、在使用weight boxes fusion这个函数的时候一样会检测boxes里的x1,y1,x2,y2是否归一化到[0:1],可以注释掉ensemble_boxes_wbf.py文件里35~64行即可使用。

4、实测效果。下面给出在多个公开数据集下,各种滤框方案和不同参数对ap的影响

coco测试集

P

R

mAP@0.5

mAP@0.5:0.95

nms use time

Soft-type

Fusion_type

skip_box_thr

NMS

0.7068

0.5759

 0.6154

 0.4228

47.11s

 

 

0.001

 

0.7068

0.5758

0.6138

0.421

93.01ms

 

 

0.0001

Soft-NMS

0.7204

0.5606

0.5968

0.4202

211.09

Gauss-0.01

 

0.0001

 

0.7218

0.5597

0.6012

0.4264

206.27

Gauss-0.01

 

0.001

 

0.7183

0.5714

0.6133

0.4265

218.7s

Gauss-0.05

 

0.0001

 

0.7219

0.5705

0.6163

0.4324

212.0s

Gauss-0.05

 

0.001

 

0.7035

0.5529

0.5995

0.4159

222.92s

Gauss-0.1

 

0.0001

 

0.7066

0.5728

0.6212

0.4304

293.8

Gauss-0.1

 

0.001

 

0.450

0.4655

0.4025

0.2906

241.71

linear

 

0.0001

 

0.4936

0.4656

0.4287

0.3082

242.23

linear

 

0.001

Weight Boxes Fusion

0.6847

0.5639

 0.5801

0.3794

405.68s

 

avg

0.0001

 

0.6803

0.5672

0.5821

0.3795

440.64s

 

avg

0.001

 

0.7093

0.5762

0.6161

0.4240

426.4s

 

max

0.0001

 

0.7093

0.5762

0.6171

0.4256

380.84s

 

max

0.001

 

0.6847

0.5639

0.5801

0.3794

418.29

 

box_and_model_avg

0.0001

 

0.6802

0.5672

0.5821

0.3794

466.73

 

box_and_model_avg

0.001

 

0.6847

0.5639

0.5801

0.3794

419.35

 

absent_model_aware_avg

0.0001

 

0.6802

0.5672

0.5821

0.3794

449.18

 

absent_model_aware_avg

0.001


【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

举报
请填写举报理由
0/200