Weighted-Boxes-Fusion

ZFTurboMIT活跃维护

把多个目标检测模型输出的检测框做融合集成,包含加权框融合(WBF)方法,能比传统 NMS 更好地合并重叠框、提升检测精度。

Set of methods to ensemble boxes from different object detection models, including implementation of "Weighted boxes fusion (WBF)" method.

v1.0.8发布于 2022-03-24 20:11 UTC1,832star236fork同步于 2026-11-08 14:53 UTC

怎么上手

由 README 提炼,执行前请确认
pip install ensemble-boxes
硬件要求按 README 说明

README 未说明,仅要求 Python 3.*、Numpy、Numba,未提及 GPU 或显存要求

下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

把多个目标检测模型的预测框融合成一套结果的 Python 库,含 WBF 等四种方法

把多个目标检测模型输出的检测框做融合集成,包含加权框融合(WBF)方法,能比传统 NMS 更好地合并重叠框、提升检测精度。

核心能力

  • 实现 NMS、Soft-NMS、NMW 与加权框融合 WBF 四种集成方法
  • 支持按模型设置权重,并按 IoU 阈值匹配跨模型框
  • 支持单模型去重、3D 框、1D 线段、旋转框与四点多边形框
  • 提供 Open Images、COCO、NLP 数据集上的多模型基准脚本

容易踩的坑

输入框坐标需归一化到 [0;1],顺序为 x1,y1,x2,y2;旋转框需用同一尺度归一化 x 和 y,否则角度会变;开发环境需先执行 source setup_dev_env.sh 创建虚拟环境

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

5 个版本v1.0.8
  1. v1.0.8Benchmark files for NLP problem最新正式版2022-03-24 · 2022-03-24 20:11 UTC

    Benchmark files for NLP problem for testing WBF 1D case.

  2. v1.0.5Benchmark files2020-07-13 · 2020-07-13 10:45 UTC
    查看更新说明

    Benchmark

  3. v1.0.4Speed up + New Features2020-06-25 · 2020-06-25 17:58 UTC
    查看更新说明
    • Added many input data checks in all methods: set to 0.0 coords < 0, set to 1.0 coords > 1, swap cases where x2 < x1 and y2 < y1, remove zero area boxes.
    • Added numba @jit(nopython=True) for critical functions (NMS, NMW and WBF). Speed up around x2 times (tested on example_oid.py).
    • Added support for 3D boxes with function weighted_boxes_fusion_3d
  4. v1.0.1Bug fix2020-06-03 · 2020-06-03 08:06 UTC
    查看更新说明

    Fixed bug with incorrect work of WBF and NMW algorithms if provided boxes was unsorted and skip_box_thr was larger than 0.0.

  5. v1.0.0First stable version2019-10-31 · 2019-10-31 07:08 UTC

    这个版本没有写更新说明。

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    DOI

    Weighted boxes fusion

    Repository contains Python implementation of several methods for ensembling boxes from object detection models:

    • Non-maximum Suppression (NMS)
    • Soft-NMS [1]
    • Non-maximum weighted (NMW) [2]
    • Weighted boxes fusion (WBF) [3] - new method which gives better results comparing to others

    Requirements

    Python 3.*, Numpy, Numba

    Installation

    pip install ensemble-boxes

    Usage examples

    Coordinates for boxes expected to be normalized e.g in range [0; 1]. Order: x1, y1, x2, y2.

    Example of boxes ensembling for 2 models below.

    • First model predicts 5 boxes, second model predicts 4 boxes.
    • Confidence scores for each box model 1: [0.9, 0.8, 0.2, 0.4, 0.7]
    • Confidence scores for each box model 2: [0.5, 0.8, 0.7, 0.3]
    • Labels (classes) for each box model 1: [0, 1, 0, 1, 1]
    • Labels (classes) for each box model 2: [1, 1, 1, 0]
    • We set weight for 1st model to be 2, and weight for second model to be 1.
    • We set intersection over union for boxes to be match: iou_thr = 0.5
    • We skip boxes with confidence lower than skip_box_thr = 0.0001
    from ensemble_boxes import *
    
    boxes_list = [[
        [0.00, 0.51, 0.81, 0.91],
        [0.10, 0.31, 0.71, 0.61],
        [0.01, 0.32, 0.83, 0.93],
        [0.02, 0.53, 0.11, 0.94],
        [0.03, 0.24, 0.12, 0.35],
    ],[
        [0.04, 0.56, 0.84, 0.92],
        [0.12, 0.33, 0.72, 0.64],
        [0.38, 0.66, 0.79, 0.95],
        [0.08, 0.49, 0.21, 0.89],
    ]]
    scores_list = [[0.9, 0.8, 0.2, 0.4, 0.7], [0.5, 0.8, 0.7, 0.3]]
    labels_list = [[0, 1, 0, 1, 1], [1, 1, 1, 0]]
    weights = [2, 1]
    
    iou_thr = 0.5
    skip_box_thr = 0.0001
    sigma = 0.1
    
    boxes, scores, labels = nms(boxes_list, scores_list, labels_list, weights=weights, iou_thr=iou_thr)
    boxes, scores, labels = soft_nms(boxes_list, scores_list, labels_list, weights=weights, iou_thr=iou_thr, sigma=sigma, thresh=skip_box_thr)
    boxes, scores, labels = non_maximum_weighted(boxes_list, scores_list, labels_list, weights=weights, iou_thr=iou_thr, skip_box_thr=skip_box_thr)
    boxes, scores, labels = weighted_boxes_fusion(boxes_list, scores_list, labels_list, weights=weights, iou_thr=iou_thr, skip_box_thr=skip_box_thr)
    
    Single model

    If you need to apply NMS or any other method to single model predictions you can call function like that:

    from ensemble_boxes import *
    # Merge boxes for single model predictions
    boxes, scores, labels = weighted_boxes_fusion([boxes_list], [scores_list], [labels_list], weights=None, method=method, iou_thr=iou_thr, thresh=thresh)
    

    More examples can be found in example.py

    3D version

    There is support for 3D boxes in WBF method with weighted_boxes_fusion_3d function. Check example of usage in example_3d.py

    1D version

    There is support for 1D line segments in WBF method with weighted_boxes_fusion_1d function. Check example of usage in example_1d.py. It was reported that 1D variant can be useful in Named-entity recognition (NER) type of tasks for Natural Language Processing (NLP) problems. Check discussion here.

    Rotated version

    There is support for rotated (oriented) boxes in WBF method with weighted_boxes_fusion_rotated function. Each box is (cx, cy, w, h, angle) with cx, cy, w, h normalized to [0; 1], and angle in degrees using the le90 (long-edge 90) convention from MMRotate (in degrees): angle in [-90, 90), with w always the longer edge. Check example of usage in example_rotated.py and in notebooks.

    Note: rotated boxes must be normalized by the same scale for both axes, e.g. divide cx, cy, w, h (in pixels) by max(image_width, image_height), or the image must be square. Normalizing x by width and y by height separately on a non-square image turns a rotated rectangle into a parallelogram and changes its angle. Multiply the fused cx, cy, w, h by the same scale to get pixels back.

    Quadrangle version

    The alternative 4-vertex declaration (x1, y1, x2, y2, x3, y3, x4, y4) used by annotation formats like DOTA and HRSC2016 is supported with weighted_boxes_fusion_quadrangle function. All 8 coordinates are normalized to [0; 1]; vertices may be given in any order/winding and are canonically re-ordered internally before fusion. Check example of usage in example_quadrangle.py and in notebooks.

    Benchmarks

    Description of WBF method and citation

    If you find this code useful please cite:

    @article{solovyev2021weighted,
      title={Weighted boxes fusion: Ensembling boxes from different object detection models},
      author={Solovyev, Roman and Wang, Weimin and Gabruseva, Tatiana},
      journal={Image and Vision Computing},
      pages={1-6},
      year={2021},
      publisher={Elsevier}
    }
    

    Adoptions

    See docs/notable adoptions.md for a list of notable projects that have used the WBF method.

    Development setup

    Clone the repo and run the setup script to create a virtual environment (wbf) and install dependencies (supports python 3.*):

    source setup_dev_env.sh
    

    To run tests:

    python -m pytest tests/