• Stars
    star
    1,719
  • Rank 27,159 (Top 0.6 %)
  • Language
    Python
  • License
    MIT License
  • Created about 5 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

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.

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}
}

More Repositories

1

Keras-RetinaNet-for-Open-Images-Challenge-2018

Code for 15th place in Kaggle Google AI Open Images - Object Detection Track
Python
266
star
2

Verilog-Generator-of-Neural-Net-Digit-Detector-for-FPGA

Verilog Generator of Neural Net Digit Detector for FPGA
Verilog
264
star
3

ZF_UNET_224_Pretrained_Model

Modification of convolutional neural net "UNET" for image segmentation in Keras framework
Python
213
star
4

volumentations

Library for 3D augmentations
Python
177
star
5

Keras-inference-time-optimizer

Optimize layers structure of Keras model to reduce computation time
Python
156
star
6

Mean-Average-Precision-for-Boxes

Function to calculate mAP for set of detected boxes and annotated boxes.
Python
121
star
7

MobileNet-in-FPGA

Generator of verilog description for FPGA MobileNet implementation
Verilog
120
star
8

MVSEP-MDX23-music-separation-model

Model for MDX23 music separation contest
Python
102
star
9

classification_models_3D

Set of models for classifcation of 3D volumes
Python
93
star
10

KAGGLE_DISTRACTED_DRIVER

Solutions
Python
93
star
11

segmentation_models_3D

Set of models for segmentation of 3D volumes
Python
89
star
12

Kaggle-Planet-Understanding-the-Amazon-from-Space

3rd place solution
Python
64
star
13

Keras-Mask-RCNN-for-Open-Images-2019-Instance-Segmentation

Code and pre-trained models for Instance Segmentation track in Open Images Dataset
Python
56
star
14

efficientnet_3D

EfficientNets in 3D variant for keras and TF.keras
Python
51
star
15

Keras-augmentation-layer

Keras implementation of layer which performs augmentations of images using GPU.
Python
49
star
16

VGG16-Pretrained-C

Pretrained VGG16 neural net in C language
C
45
star
17

2nd-place-solution-for-VinBigData-Chest-X-ray-Abnormalities-Detection

Localization of thoracic abnormalities model based on VinBigData (top 1%)
Python
36
star
18

KAGGLE_CERVICAL_CANCER_2017

Python
33
star
19

DrivenData-Alzheimer-Research-1st-place-solution

1st place solution for Clog Loss: Advance Alzheimer’s Research with Stall Catchers
Python
22
star
20

classification_models_1D

Classification models 1D Zoo - Keras and TF.Keras
Python
13
star
21

DrivenData-Identify-Fish-Challenge-2nd-Place-Solution

Solution for N+1 fish, N+2 fish DrivenData competition (2nd place)
Python
12
star
22

Covid-19-spread-prediction

Automatic short-term covid-19 spread prediction by countries and Russian regions
Python
10
star
23

MVSEP-CDX23-Cinematic-Sound-Demixing

Model for CDX23 (Cinematic Sound Demixing) contest
Python
9
star
24

DrivenData-Pri-matrix-Factorization-2nd-Place-Solution

DrivenData Pri-matrix Factorization (2nd place solution)
Python
8
star
25

DrivenData-Open-AI-Caribbean-Challenge-2nd-place-solution

Code for DrivenData Open AI Caribbean Challenge. 2nd place solution.
Python
7
star
26

VOTS2023-Challenge-Tracker

Code for VOTS2023 Challenge tracker
Python
7
star
27

KAGGLE_AVITO_2016

Avito Duplicate Ads Detection
Python
6
star
28

MobileNet-v1-Pytorch

MobileNet v1 in Pytorch. Weights converted from Keras implementation
Python
5
star
29

Post-Training-Integer-Quantization

Some examples of quantization process
Python
3
star
30

Audio-separation-models-checker

Python
3
star
31

demucs3

Fork of demucs repository
Python
3
star
32

KAGGLE_YELP

Solutions
Python
3
star
33

KAGGLE_DSB2

Solutions
Python
1
star
34

Pretrained-VGG-neural-nets-in-TensorFlow

Set of VGG neural net models for TensorFlow. Weights converted from Pytorch.
Python
1
star